标题:哪位大牛看帮忙给解决关于多线程并发数据包的问题嘛,快被整疯了
只看楼主
cjb8421
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2019-5-20
 问题点数:0 回复次数:0 
哪位大牛看帮忙给解决关于多线程并发数据包的问题嘛,快被整疯了
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)
程序启动后并没有发送数据包但是程序是正常执行的,看到的大佬麻烦给出个解决的注意呗


搜索更多相关主题的帖子: 数据包 from import IP Process 
2019-05-20 21:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-494848-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.782575 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved