python脚本-探查存活主机
代码
from scapy.all import *
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
net="10.9.47."
# 此处修改目标网段
for host in range(1,255):
ip=f"{net}{host}"
# print(f"[-]Tring ip {ip}")
# 解除上一行注释即可看到探查过程,但是结果会被分散
pkt=IP(src="10.4.7.138",dst=f"{ip}")/ICMP()
# 此处src的内容为源ip
res=sr1(pkt,timeout = 0.2, verbose = False)
if res:
print(f"[+]Alive {ip}")