0

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.

GreenGodot
  • 6,030
  • 10
  • 37
  • 66
  • 2
    Edit your question and show your network setup and network interface setup. Remember that public IP addresses are not actually bound to your network interfaces. Public IPs are bound to a special type of one-to-one NAT device. Show the routes as defined inside the instance. You probably have one default route which handles all outbound traffic. Show real code and not pseudo code in your question. – John Hanley Feb 24 '20 at 18:04
  • Have a look at the documentation to find more details **Routing order** https://cloud.google.com/vpc/docs/routes#routeselection – Serhii Rohoza Mar 04 '20 at 12:01

0 Answers0