0

I have a script that sends traffic to a server. It marks incoming traffic as known location traffic for a specific IP.

My script sends traffic via Pycurl. I cannot change Pycurl for now, so is there any way to send traffic by sending that specific source IP.

Options are either set source IP in pycurl or make it use some interface which is created with that specific IP. I need to know how to make a virtual interface to serve traffic for the specific IP in python so that pycurl picks up that interface to send.

1 Answers1

0

If you have multiple interfaces with multiple IP addresses or if you just want the kernel to handle this, you just need to add a host route in your kernel. On linux, this would look something like:

ip route add 10.45.0.20/32 src 10.45.0.10

Where 10.45.0.10 is the IP you want as a source and 10.45.0.20 is the webserver. Note: if you have a gateway to get to the server, then you need to have a 'via' statement and the desired source ip needs to be able to send traffic to it (same subnet).

If you have multiple interfaces and the ip you want to use is the only one bound to one of those interfaces, then you can just add the following to your Pycurl program:

c = pycurl.Curl()
...
c.setopt(pycurl.INTERFACE, "eth2")

Where eth2 is the name of the interface the request will come from. If the IP you want as a source is the only one bound to eth2, then the request will have that source IP.

Liam Kelly
  • 3,524
  • 1
  • 17
  • 41