编写一个脚本test_ip.py
实现指定参数的远程主机网络探测
python test_ip.py 192.168.0.10 192.168.0.100
针对192.168.0.10~192.168.0.100范围内所有主机进行网络探测
python">import sys
import time获取命令行参数:python test_ip.py 192.168.0.10 192.168.0.100
initial_ip = sys.argv[1]
end_ip = sys.argv[2]
拆分ip
root_ip = initial_ip.rsplit('.', 1)[0]
init_ip = int(initial_ip.rsplit('.', 1)[1])
e_ip = int(end_ip.rsplit('.', 1)[1])# for循环便利ip地址
for ip in range(init_ip, e_ip + 1):# 拼接ipprint(f"开始扫描{root_ip}.{ip}")# 模拟扫描时间time.sleep(0.1)print(f"{root_ip}.{ip}扫描完成,网络畅通")