Created
March 23, 2010 15:41
-
-
Save pentikos/341307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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