Skip to content

Instantly share code, notes, and snippets.

@heppu
Created January 30, 2015 19:25
Show Gist options
  • Save heppu/24aecd3205608fad12f0 to your computer and use it in GitHub Desktop.
Save heppu/24aecd3205608fad12f0 to your computer and use it in GitHub Desktop.
# -*- coding: UTF-8 -*-
import sys
import socket
import sys
import socket
import time
def stringToDict(data):
arr = data.split('\r\n')
dick = {}
for i in range(1, len(arr)-1):
dick[arr[i][0:arr[i].index(':')]] = arr[i][arr[i].index(':')+2:]
return dick
def main():
ip = '188.166.63.53 33443'
port = 33443
#create udp connection
udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_sock.bind(('', port))
hello = 'HELLO REQUEST SEP/1.0\r\nUSER-AGENT: a\r\nTIME: %s\r\n' %((int(time.time())+120))
udp_sock.sendto(hello, (ip, port))
data = udp_sock.recv(1024)
mapped = stringToDict(data)
ID = mapped['ID']
echo = 'ECHO REQUEST SEP/1.0\r\nUSER-AGENT: a\r\nTIME: %s\r\nID: %s\r\nECHO-LENGTH: %s\r\nECHO: 00000000' %((int(time.time())+120), ID, 15768)
udp_sock.sendto(echo, (ip, port))
data = udp_sock.recv(12000)
print data
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment