#coding=utf-8
import ctypes
libgcc_s = ctypes.CDLL('libgcc_s.so.1')
import socket
import threading
# 定义IP地址和端口范围
ip_address = "192.168.1.45"
start_port = 1
end_port = 50000
# 定义扫描函数
def scan_port(port):
try:
# 创建socket对象并尝试连接到指定端口
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((ip_address, port))
if result == 0:
print(f"Port {port} is open")
sock.close()
except:
pass
while True:
# 创建线程并调用扫描函数
for port in range(start_port, end_port+1):
t = threading.Thread(target=scan_port, args=(port,))
t.start()