-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.py
52 lines (44 loc) · 1.54 KB
/
Client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
__author__ = 'Rafael S. Guimarães e João Paulo de Brito Gonçalves'
import hashlib
import struct
import socket
from server.ClientP2P import ClientP2P
def ip2int(addr):
return struct.unpack("!I", socket.inet_aton(addr))[0]
def int2ip(addr):
return socket.inet_ntoa(struct.pack("!I", addr))
def main():
res = hashlib.md5()
res.update(str('192.168.0.22'))
p2pClient = ClientP2P("127.0.0.1")
## ENVIO
#data = struct.pack("!BI",0,2323)
#p2pClient.sendMessage(data)
#data = struct.pack("!BIIIII",1,2222,2323,ip2int("192.168.0.1"),2424,ip2int("192.168.0.2"))
#p2pClient.sendMessage(data)
#data = struct.pack("!BIII",2,2222,ip2int("127.0.0.22"),2323)
#p2pClient.sendMessage(data)
#data = struct.pack("!BIII",3,2222,2424,ip2int("177.2.2.1"))
#p2pClient.sendMessage(data)
## RECEBIMENTO
#data = struct.pack("!BIIII",64,2323,ip2int("177.2.2.1"),2424,ip2int("177.2.2.33"))
#p2pClient.sendMessage(data)
#data = struct.pack("!BI",65,2323)
#p2pClient.sendMessage(data)
#data = struct.pack("!BIII",66,2323,2424,ip2int("177.2.2.1"))
#p2pClient.sendMessage(data)
rmsg = {
'dest_ip_addr': '127.0.0.1',
'type': 2,
'src_id_searched': 1222,
'src_ip_searched': '127.0.0.1',
'id_searched': 1222,
}
p2pClient.sendLookupMsg(rmsg)
#data = struct.pack("!BI",67,2323)
#p2pClient.sendMessage(data)
#bytes("64"+str(int(res.hexdigest(),16))[0:]))
#+str(int(res.hexdigest(), 16))
if __name__ == "__main__":
main()