全部博文(362)
分类: Python/Ruby
2011-06-09 19:51:50
zhengsenlin8882011-06-09 20:32:41
#!/usr/bin/env python # name IsOpen.py import os import socket def IsOpen(ip): for port in range(1,500): s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) try: s.connect((ip,int(port))) #s.shutdown(2) print '%d is open' % port #return True except: print '%d is down' % port #return False if __name__ == '__main__': IsOpen('2.2.2.2')