/
client.py
56 lines (38 loc) · 1.16 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
53
54
55
56
import sys
from networking import Client
infilename = 'PROJ2-HNS.txt'
outfilename = 'RESOLVED.txt'
datalength = 200
lsHostname = None
lsListenPort = None
def queryHostNames(lsclient):
global lsHostname
global lsListenPort
# Open file of hostnames to query
infile = open(infilename, 'r')
outfile = open(outfilename, 'w+')
lines = infile.readlines()
lsclient.connecttoserver(lsHostname, lsListenPort)
for index in range(len(lines)):
hostname = lines[index].strip()
request = hostname.lower().encode('utf-8')
print '[C]: RS request: ', request
lsclient.socket.send(request)
response = lsclient.socket.recv(datalength).decode('utf-8')
print 'RESPONSE: ', response
if index != len(lines) - 1:
outfile.write(response + '\n')
else:
outfile.write(response)
lsclient.close()
def main():
args = sys.argv
if len(args) != 3: print 'Insufficient Arguments'
global lsHostname
global lsListenPort
lsHostname = args[1]
lsListenPort = int(args[2])
lsclient = Client()
queryHostNames(lsclient)
if __name__ == "__main__":
main()