Exemple #1
0
class EchoClient(object):

    def __init__(self):
        self.transport = TCPClient("64.4.35.253", 7001)
        self.transport.connect("notify::status", self.on_status_changed)
        self.transport.connect("error", self.on_error)
        self.transport.connect("received", self.on_received)
        gobject.idle_add(self.open)

    def open(self):
        self.transport.open()

    def on_status_changed(self, transport, param):
        status = transport.get_property("status")
        print status
        if status == IoStatus.OPEN:
            print self.transport.sockname
            request = "\x02\x01\x41\x31\x41\x31\x41\x31\x00\x00\x00\x00\x00\x00\x00\x00\x5d\x00\x00\x00"
            self.transport.send(request)

    def on_error(self, transport, error):
        print "error", error

    def on_received(self, transport, data, lenght):
        fields = struct.unpack("!BBHIHHII", data)
        ver, code, port, ip, discard_port, test_port, test_ip, tr_id = fields
        port ^= 0x4131
        print repr(data)
        print ip
        ip ^= 0x41314131
        ip = socket.inet_ntoa(struct.pack("!I", ip))
        print ip, port
Exemple #2
0
 def __init__(self):
     self.transport = TCPClient("64.4.35.253", 7001)
     self.transport.connect("notify::status", self.on_status_changed)
     self.transport.connect("error", self.on_error)
     self.transport.connect("received", self.on_received)
     gobject.idle_add(self.open)