共计 609 个字符,预计需要花费 2 分钟才能阅读完成。
由于某次使用禁用了主机的以太网,开启了无线网,导致平常使用的以太网固定 ip 不能连接了,但是知道无线网所在网段,所以通过其他机器执行以下脚本进行扫描,再尝试登陆。
#!/usr/bin/env python3
import ipaddress
import socket
import concurrent.futures
def scan_port(ip, port=3389, timeout=1):
"""扫描指定 IP 的端口是否开放"""
try:
with socket.create_connection((str(ip), port), timeout=timeout):
print(f"✅ {ip}:{port} 已开启")
except:
pass
def main():
network = "172.21.9.0/24" # 固定网段
network_obj = ipaddress.ip_network(network, strict=False)
print(f"开始扫描网段 {network} 中开启 3389 端口的主机...")
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
for ip in network_obj.hosts():
executor.submit(scan_port, ip)
print("扫描完成。")
if __name__ == "__main__":
main()
AD:【腾讯云服务器大降价】2核4G 222元/3年 1核2G 38元/年
正文完