Python 官方文档:入门教程 => 点击学习
#coding:utf8import Socket,time,re,thread,ostimeout=3socket.setdefaulttimeout(timeout)def socket_port(ip,port): s=sock
#coding:utf8
import Socket,time,re,thread,os
timeout=3
socket.setdefaulttimeout(timeout)
def socket_port(ip,port):
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
result=s.connect_ex((ip,port))
if result==0:
lock.acquire()
print '%s'%ip+',%s端口通过'%port+'\n'
lock.release()
s.close()
else:
print '%s'%ip+',%s端口异常'%port+'\n'
def ip_scan(ip):
print"""
*****************************************
端口号为 21,22,23,3389,1521,3940
*****************************************
"""
try:
print '开始扫描 %s'%ip
list1=[21,22,23,3389,1521,3940,]
start_time=time.time()
for i in list1:
thread.start_new_thread(socket_port,(ip,int(i)))
print "扫描端口完成,总共用时:%.2f"%(time.time()-start_time)+'\n'
except:
print "扫描IP出错"
if __name__=='__main__':
url=open('C:\Users\Jia\Desktop\IP,Port.txt','r')
url1=url.read()
url2=re.findall(r'[\d]+.+[^\W]',url1)
url.close()
for x in url2:
lock=thread.allocate_lock()
ip_scan(x)
time.sleep(5)
--结束END--
本文标题: python socket 端口测试
本文链接: https://www.lsjlt.com/news/190681.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0