-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathringer.py
executable file
·60 lines (47 loc) · 1.27 KB
/
ringer.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
53
54
55
56
57
58
59
60
#!/usr/bin/python
import socket
import sys
import struct
import time
debug=1
#main function
if __name__ == "__main__":
if(len(sys.argv) < 2) :
print 'Usage : python client.py hostname'
sys.exit()
host = sys.argv[1]
port = 9999
#create an INET, STREAMing socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(3)
except socket.error:
print 'Failed to create socket'
sys.exit()
#print 'local Socket Created'
try:
print 'ringing : ' + host
remote_ip = socket.gethostbyname( host )
s.connect((host, port))
except socket.gaierror:
print 'Hostname could not be resolved. Exiting'
sys.exit()
except socket.error:
if debug: print "could not contact " + host
sys.exit()
#print 'Socket Connected to ' + host + ' on ip ' + remote_ip
s.settimeout(None)
#Send some data to remote server
# make it like a "PSK" kind of thing
message = "Q60NQzca32NU8zUuEOSPHmnnXKsSJNereT71yBNcgSAxj4TYqeAxOQAXnWn1jXs"
#message = "Q6NQzca32NU8zUuEOSPHmnnXKsSJNereT71yBNcgSAxj4TYqeAxOQAXnWn1jXs"
try :
s.send(message)
if debug: print 'Key sent successfully'
except socket.error:
#Send failed
if debug: print 'receive failed'
sys.exit()
data = s.recv(1024)
if debug: print data+"\n"
s.close()