-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathServerLoader.py
executable file
·78 lines (61 loc) · 1.85 KB
/
ServerLoader.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
import socket
import sys
import os
import time
import ConfigParser
config = ConfigParser.ConfigParser ()
config.read ("ServerLoader.ini")
def ConfigSectionMap(section):
dict1 = {}
options = config.options(section)
for option in options:
try:
dict1[option] = config.get(section, option)
if dict1[option] == -1:
print("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
def main():
PATH = ConfigSectionMap("serverloader")['path']
request = ConfigSectionMap("serverloader")['request_msg']
response = ConfigSectionMap("serverloader")['response_msg']
print PATH
if len(sys.argv) != 3:
print ("usage: ServerLoader <scam ip> <scam port>")
sys.exit()
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = (sys.argv[1], int(sys.argv[2]))
print 'connecting to %s port %s' % server_address
while True:
try:
sock.connect (server_address)
break
except:
print "Oops! SCAM not found, Trying again..."
time.sleep(5)
print 'Connected!'
try:
# Send data
print 'sending "%s"' % request
sock.sendall(request)
# Look for the response
amount_received = 0
amount_expected = len(response)
while True:
data = sock.recv(16)
# amount_received = len(data)
print 'received "%s"' % data
if data == response:
sock.send("ack")
break
os.system(PATH)
finally:
print 'closing socket'
sock.close()
if __name__ == "__main__":
sys.exit(main())