Python多线程扫描端口代码示例
作者:douyunqian668 时间:2021-09-26 10:32:39
本文代码实现Python多线程扫描端口,具体实现代码如下。
#coding:utf-8
import socket
import thread
import time
socket.setdefaulttimeout(3)
def socket_port(ip,port):
try:
if port>=65535:
print(u"端口扫描结束!")
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)#创建套接字
result=s.connect_ex((ip,port))#链接端口
if(result==0):
print ip,u" : ",port,u"端口开发"
s.close()
except:
print(ip,":",port)
print(u"端口扫描异常")
def IP_port(data):
try:
ip="127.0.0.1"
t=time.time()
for i in range(0,1000+1):
thread.start_new_thread(socket_port,(ip,int(i)))#多线程扫描端口
time.sleep(0.003)
print(u"扫描端口完成用时:time_:%s"%(time.time()-t))
except Exception as e:
print(e)
print(ip,i)
print(u"端口扫描异常")
if __name__ == '__main__':
print u"开始工作"
# socket_port("127.0.0.1",135)
IP_port("127.0.0.1")
结果如下:
开始工作
127.0.0.1 : 135 端口开发
127.0.0.1 : 445 端口开发
扫描端口完成用时:time_:3.00300002098
>>>
来源:http://blog.csdn.net/douyunqian668/article/details/72850953
标签:python,多线程,端口
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Symfony核心类概述
2023-11-17 13:59:48
![](https://img.aspxhome.com/file/2023/7/92807_0s.png)
web标准页面知识必备 Ⅰ
2008-03-06 13:24:00
python实现神经网络感知器算法
2021-03-06 11:23:39
![](https://img.aspxhome.com/file/2023/9/91979_0s.png)
深入认识javascript中的eval函数
2008-08-03 16:44:00
Python实现图形用户界面计算器
2022-09-02 06:07:22
![](https://img.aspxhome.com/file/2023/7/70257_0s.jpg)
给Notepad++换主题
2009-05-04 14:43:00
![](https://img.aspxhome.com/file/UploadPic/20095/4/rhtml-39s.gif)
Python+OpenCV之形态学操作详解
2021-11-24 23:37:58
![](https://img.aspxhome.com/file/2023/4/86624_0s.png)
MS SQL 查询数据在数据库中所在行
2009-04-26 19:36:00
官方是这样定义 DOCTYPE HTML PUBLIC 的
2007-05-31 09:43:00
python实现KNN分类算法
2023-03-01 07:53:36
![](https://img.aspxhome.com/file/2023/2/90702_0s.jpg)
Python如何基于smtplib发不同格式的邮件
2023-10-03 10:28:35
各种SQL语句速查手册
2007-09-27 19:31:00
详解基于python的全局与局部序列比对的实现(DNA)
2021-03-29 13:23:31
![](https://img.aspxhome.com/file/2023/9/68479_0s.png)
python实现CTC以及案例讲解
2023-04-18 22:04:13
![](https://img.aspxhome.com/file/2023/6/92176_0s.png)
Python与Matlab混合编程的实现案例
2023-01-14 14:44:39
![](https://img.aspxhome.com/file/2023/7/103467_0s.png)
HTML中事件触发列表与解说
2007-10-22 12:50:00
SQL 2008的变更数据捕获——跟踪可变部分
2009-03-20 11:47:00
![](https://img.aspxhome.com/file/UploadPic/20093/2009322183639136.jpg)
python 安装移动复制第三方库操作
2022-01-20 06:43:09
![](https://img.aspxhome.com/file/2023/9/91919_0s.jpg)
ASP经常用到的函数
2009-07-06 13:00:00
关于利用:first-letter实现首字下沉的一些看法
2010-04-20 17:19:00
![](https://img.aspxhome.com/file/UploadPic/20104/20/first-letter_no_float-38s.png)