查看端口状态的python代码
2018-07-20 来源:open-open
#coding:utf-8 import socket import threading import time class SkPort(threading.Thread): def __init__(self,ip,port): threading.Thread.__init__(self) self.ip = ip self.port = port def run(self): sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sk.settimeout(1000) try: sk.connect((self.ip,self.port)) print('Server %s port %d OK!' % (self.ip,self.port)) except Exception: # print('Server %s port %d is not connected!' % (self.ip,self.port)) error = self.port sk.close() def main(): ip = '127.0.0.1' sport = int(raw_input('begin port:')) eport = int(raw_input('end port:')) for port in range(sport,eport+1): item = (ip,port) t = SkPort(ip,port) t.start() if __name__ == '__main__': main()
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐