#!/usr/bin/env python
import thread
import socket
import sys
IP=[156,192,172,192,151,152]
Network=sys.argv[1:][0]
def Scan(Point,lock):
Addr=str(Network) +'.'+ str(Point)
for Port in range(20000):
try:
socket.setdefaulttimeout(1)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((Addr,Port))
print "%s port %d is UP." % (Addr,Port)
sock.close()
except:
null=open('/dev/null','w')
print >> null,str
lock.release()
def main():
locks=[]
NIP=range(len(IP))
for num in NIP:
lock=thread.allocate_lock()
lock.acquire()
locks.append(lock)
for num in NIP:
thread.start_new_thread(Scan,(IP[num],locks[num]))
for num in NIP:
while locks[num].locked():
pass
if __name__ == '__main__':
main()
转载于:https://blog.51cto.com/wlgcsrhl/1391986