I am trying to run a script that sends traffic from 2 or 3 IP addresses at the same time. I have set up the script on a GCE platform running Ubuntu. I am using aiohttp to asynchronously send a scalable X amount of requests to a specfic endpoint.
def fetch(url_query, session):
#build URL query
async with session.get(search_query_feed_url, headers=headers) as response:
response_string = await response.text()
return response_string
.................
.................
.................
async def fetch_all(kw_list, loop, num_connections):
connector = TCPConnector(limit=num_connections) #local testing method
async with ClientSession(loop=loop, connector=connector) as session:
results = await asyncio.gather(*[fetch(query_argument, session) for kw in kw_list], return_exceptions=False) #run awaitable functions concurrently
return results
What I want is to, after a certain period of time, switch what network interface card my machine uses to send and receive traffic. In my (admittedly Beginner) GCE setup, I have a VM instance deployed and connected to several VPC networks, each with their own ephemeral external IP defined. Multiple NICs are confirmed to be connected to my instance and I can see the internal IP they are broadcasting on. How would I go about defining in the above code what NIC to use for the requests?
My initial effort involved setting the local_addr
argument for TCPConnector to be the internal IP of the network interface itself. This does not seem to work however, as the endpoint of this experiment shows the request coming from the same external IP as always (the default one).
I'm a bit new to using multiple IP's on one machine so my lingo may not be correct. Any pointers here would be appreciated.