哪位大牛看帮忙给解决关于多线程并发数据包的问题嘛,快被整疯了
from kamene.all import*from random import randint
def scapy_ping_one(host):
id_ip = randint(1,65535)
id_ping =randint(1,65535)
seq_ping = randint(1,65535)
packet = IP(dst = host,ttl = 64,id = id_ip)/ICMP(id = id_ping,seq = seq_ping)/b"cjb"
ping = sr1(packet,timeout = 2,verbose = False)
if ping:
ping.show()
os._exit(3)
if __name__ == "__main__":
import sys
scapy_ping_one(sys.argv[1])
import logging
logging.getLogger("kamene.runtime").setLevel(logging.ERROR)
from ipaddress import*
from time import time
from multiprocessing import*
from scapy_ping_one import scapy_ping_one
from kamene.all import*
def scapy_ping_scan(network):
net = ip_network(network)
ip_processes = {}
for ip in net:
ip_addr = str(ip)
ping_one = Process(target = scapy_ping_one,args = (ip_addr,))
ping_one.start()
ip_processes[ip_addr] = ping_one
ip_list=[]
for ip,process in ip_processes.items():
if process.exitcode == 3:
ip_list.append(ip)
else:
process.terminate()
return sorted(ip_list)
if __name__ == "__main__":
active_ip = scapy_ping_scan("1.1.1.0/24")
print("活动的ip地址如下")
for ip in active_ip:
print(ip)
程序启动后并没有发送数据包但是程序是正常执行的,看到的大佬麻烦给出个解决的注意呗