Skip to content

Instantly share code, notes, and snippets.

@pentikos
Created March 23, 2010 15:41
Show Gist options
  • Save pentikos/341307 to your computer and use it in GitHub Desktop.
Save pentikos/341307 to your computer and use it in GitHub Desktop.
import socket, ssl, struct
from eppxml.hello import Hello
class Client(object):
def connect(self, host, port):
self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection.setblocking(0)
self.connection.settimeout(10)
self.connection = ssl.wrap_socket(self.connection)
try:
self.connection.connect((host, port))
return True
except socket.timeout:
return False
def hello(self):
base = Hello()
xml = base.output()
self.write(xml)
return self.read()
def write(self, xml):
header = struct.pack(">i", len(xml))
content = header + xml
self.connection.sendall(content)
def read(self):
length = None
data = ""
i = 0
while length == None or length > 0:
i = i + 1
if not length:
header = self.connection.recv(4)
length = struct.unpack('>i', header)[0]-4
else:
line = self.connection.recv(1024)
data += line
length -= len(line)
return data
def close(self):
self.connection.close()
if __name__ == "__main__":
client = Client()
connected = client.connect("testdrs.domain-registry.nl", 700)
if connected:
print client.hello()
client.close()
else:
print 'Failed'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment