from socket import * from struct import * from optparse import OptionParser
def main(hostname,port): s = socket(AF_INET,SOCK_STREAM) s.connect((hostname,port))
result = 0 for i in range(4): rec = s.recv(4) num = unpack(" print "num[%d]:%d"%(i,num) result += num print str(result)
s.send(pack(" print s.recv(1024) s.close()
if __name__=="__main__": parse = OptionParser("usage: %prog [options]") parse.add_option("-H",dest="hostname",default="127.0.0.1",type="string",help="The ip of the target") parse.add_option("-P",dest="port",default=2997,type="int",help="The port of the host")
(options,args)=parse.parse_args()
main(options.hostname,options.port)
运行结果:
D:\Python27\a\protostar>debug.py -H 192.168.0.71 num[0]:605764919 num[1]:1932937542 num[2]:278220490 num[3]:835448954 3652371905 you added them correctly