python3.4端口检测:

python3.4端口检测:

import sys,time,socket
#a='sys.argv[0]'
#b='sys.argv[1]'
#c='sys.argv[2]'
while 1:
    try:
        time.sleep(2)
        sc=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        ip = sys.argv[1]
        port = int(sys.argv[2])
        sc.settimeout(0.5)
        sc.connect((ip,port))
        print (ip,':',port,'成功!')
        
    except KeyboardInterrupt:
        break
        
    except:
        print(ip,':',port,'失败!')
#print (a,b,c)
#os.system('pause')
import sys,time,socket
#example: test.py   x.x.x.x   80
while 1:
    #time.sleep(0.8)
    try:
        time.sleep(1)
        sc=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        ip = sys.argv[1]
        port = int(sys.argv[2])
        sc.settimeout(0.5)
        sc.connect((ip,port))
        print (ip,':',port,':OK')     
    except socket.timeout:
        print(ip,':',port,':Fail')
                
    #except KeyboardInterrupt:
    #    break
    except:
        break

python3.4端口检测:

你可能感兴趣的:(python3.4端口检测:)