nando client p3
This commit is contained in:
30
nando
30
nando
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import socket,sys,time,os,configobj
|
||||
|
||||
@@ -39,11 +39,11 @@ def setup_options():
|
||||
if options.MSGFILE is None:
|
||||
if "MSGFILE" in rc.keys():
|
||||
options.MSGFILE=rc['MSGFILE']
|
||||
|
||||
|
||||
if options.HOST is None:
|
||||
parser.error("Host name required")
|
||||
parser.error("Host name required")
|
||||
if options.PORT is None:
|
||||
parser.error("Port number required")
|
||||
parser.error("Port number required")
|
||||
return options
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ def query_ip(sock,opts):
|
||||
sys.stdout.write(cols[1])
|
||||
sys.exit(0)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def query_host(sock,opts):
|
||||
sock.sendto("list", (opts.HOST, opts.PORT))
|
||||
received = sock.recv(BLOCK_SIZE)
|
||||
@@ -83,14 +83,14 @@ def query_host(sock,opts):
|
||||
sys.exit(1)
|
||||
|
||||
def read_desc(opts):
|
||||
|
||||
|
||||
if not opts.MSGFILE:
|
||||
return ""
|
||||
if not os.path.isfile(opts.MSGFILE):
|
||||
return ""
|
||||
|
||||
|
||||
DESC=open(opts.MSGFILE,"rb").read(1024)
|
||||
DESC=''.join([ c for c in DESC if c not in ['\n','\r','|'] ])
|
||||
DESC=''.join([ str(c) for c in DESC.decode('utf-8') if c not in ['\n','\r','|'] ])
|
||||
return DESC
|
||||
|
||||
opts=setup_options()
|
||||
@@ -103,26 +103,26 @@ while True:
|
||||
sock.settimeout(opts.TIMEOUT)
|
||||
sock.connect((opts.HOST,opts.PORT))
|
||||
MYIP=sock.getsockname()[0]
|
||||
|
||||
|
||||
if opts.QUERY_HOSTNAME:
|
||||
query_ip(sock,opts)
|
||||
if opts.QUERY_IP:
|
||||
query_host(sock,opts)
|
||||
|
||||
|
||||
if opts.command=="":
|
||||
DESC=read_desc(opts)
|
||||
MSG="{0}|{1}|{2}\n".format(MYNAME,MYIP,DESC)
|
||||
else:
|
||||
MSG=opts.command
|
||||
|
||||
sock.sendto(MSG, (opts.HOST, opts.PORT))
|
||||
|
||||
sock.sendto(MSG.encode('utf8'), (opts.HOST, opts.PORT))
|
||||
received = sock.recv(BLOCK_SIZE)
|
||||
if opts.command!="":
|
||||
print_table(received)
|
||||
print_table(received.decode('utf8'))
|
||||
if opts.INTERVAL==0 and opts.command=="":
|
||||
sock.sendto("list", (opts.HOST, opts.PORT))
|
||||
sock.sendto("list".encode('utf8'), (opts.HOST, opts.PORT))
|
||||
received = sock.recv(BLOCK_SIZE)
|
||||
print_table(received)
|
||||
print_table(received.decode('utf8'))
|
||||
errors=0
|
||||
except socket.error:
|
||||
print("Didn't get reply from {0}:{1}".format(opts.HOST,opts.PORT))
|
||||
|
||||
Reference in New Issue
Block a user