Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Python library than can simulate network traffic from different addresses

Tags:

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.

like image 503
readonly Avatar asked Jan 05 '09 18:01

readonly


People also ask

How traffic generator works?

Basics of Traffic Generators Traffic generators are a way of injecting traffic into a network for utilization by other devices. A traffic generator is meant to look like a device on a network, so it can target devices in receipt of traffic. This means it will have a physical, typically higher-level address.

How do I simulate network congestion?

You should use a traffic generator like IXIA's http://www.ixiacom.com/ traffic generator for this. This device allows you to create test cases with different loads on the network, both pointing at your application and just overall network congestion. You can even simulate network attacks on your application.


1 Answers

You can spoof an IP address using Scapy library.

Here's an example from 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 :-)"
like image 90
jfs Avatar answered Oct 06 '22 14:10

jfs