python-端口扫描
程序员文章站
2022-05-15 22:09:28
...
环境: python3
# 1. 定义portscan函数,用来进行TCP 端口扫描
# 2.启动多线程进行扫描函数
import socket
from threading import Thread
import time
def main(target):
print("开始扫描: %s" %target)
for port in range(1,5000): #定义扫描端口的范围
t=Thread(target=portscan,args=(target,port))
t.start()
# 1.定义portscan函数,用来进行TCP端口扫描
def portscan(target,port):
try:
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect((target,port))
print("[*] %s:%d开放" %(target,port))
client.close()
except:
pass
if __name__ == '__main__':
target=input("请输入你要扫描的IP或网址: ")
start=time.time()
main(target)
end=time.time()
print("总共耗时: %.2f s" %(end-start))
演示:
上一篇: 端口扫描实验
下一篇: python-端口扫描