mirror of
https://github.com/r4sas/Niflheim-api
synced 2025-03-13 05:51:45 +00:00
Create send-view.py
This commit is contained in:
parent
16444c9d35
commit
35a27860d6
40
send-view.py
Normal file
40
send-view.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import socket
|
||||||
|
import json
|
||||||
|
|
||||||
|
GETDHT = '{"request":"getDHT", "keepalive":true}'
|
||||||
|
GETSWITCHPEERS = '{"request":"getSwitchPeers"}'
|
||||||
|
SERVER = "y.yakamo.org"
|
||||||
|
|
||||||
|
|
||||||
|
def send_view_to_server(tosend):
|
||||||
|
if tosend:
|
||||||
|
attempts = 3
|
||||||
|
while attempts:
|
||||||
|
try:
|
||||||
|
conn = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
conn.sendto(tosend, (SERVER, 45671))
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
attempts -= 1
|
||||||
|
|
||||||
|
|
||||||
|
def collect_dht_getswitchpeers():
|
||||||
|
try:
|
||||||
|
ygg = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
ygg.connect(('localhost', 9001))
|
||||||
|
|
||||||
|
ygg.send(GETDHT)
|
||||||
|
dhtdata = json.loads(ygg.recv(1024 * 15))
|
||||||
|
|
||||||
|
ygg.send(GETSWITCHPEERS)
|
||||||
|
switchdata = json.loads(ygg.recv(1024 * 15))
|
||||||
|
|
||||||
|
temp_dict = {}
|
||||||
|
temp_dict["dhtpack"] = dhtdata
|
||||||
|
temp_dict["switchpack"] = switchdata
|
||||||
|
|
||||||
|
return json.dumps(temp_dict).encode()
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
send_view_to_server(collect_dht_getswitchpeers())
|
Loading…
x
Reference in New Issue
Block a user