【问题标题】:Is there a Python library than can simulate network traffic from different addresses是否有 Python 库可以模拟来自不同地址的网络流量
【发布时间】:2010-09-29 15:58:55
【问题描述】:

是否有一个 python 库可以让我从不同的源地址和端口向机器发送 UDP 数据包(发送到本地主机是可以的)?我记得有一个,但现在找不到了。

【问题讨论】:

    标签: python networking


    【解决方案1】:

    您可以使用 Scapy 库来欺骗 IP 地址。

    这是来自Packet Wizardry: Ruling the Network with Python的示例:

    #!/usr/bin/env python
    import sys
    from scapy import *
    conf.verb=0
    
    if len(sys.argv) != 4:
        print "Usage: ./spoof.py <target> <spoofed_ip> <port>"
        sys.exit(1)
    
    target = sys.argv[1]
    spoofed_ip = sys.argv[2]
    port = int(sys.argv[3])
    
    p1=IP(dst=target,src=spoofed_ip)/TCP(dport=port,sport=5000,flags='S')
    send(p1)
    print "Okay, SYN sent. Enter the sniffed sequence number now: "
    
    seq=sys.stdin.readline()
    print "Okay, using sequence number " + seq
    
    seq=int(seq[:-1])
    p2=IP(dst=target,src=spoofed_ip)/TCP(dport=port,sport=5000,flags='A',
                                         ack=seq+1,seq=1)
    send(p2)
    
    print "Okay, final ACK sent. Check netstat on your target :-)"
    

    【讨论】:

    • 这正是我想要的。谢谢!
    • 哦,我的喜欢。得看看 scapy。
    • 数据包将被内核丢弃或被 NAT/FIREWAL 过滤或被 ISP 杀死,但您的回答非常好。
    • 这基本上对我有用,但我需要from scapy.all import *
    猜你喜欢
    • 1970-01-01
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 2010-10-10
    • 1970-01-01
    • 2020-07-29
    相关资源
    最近更新 更多