I have a VM as a server with IP address 10.91.55.2. I have another VM which acts as a client having IP address in the range 10.91.56.2......10.91.56.10. I want to write a script that will use all these IP address on the client to send HTTP request to the server (10.91.55.2). I have written a script that sends HTTP requests using the Physical IP address alone. Is there any way to send HTTP Requests from a range of IP address. My OS Is linux.
This is not a complete answer, but should provide you with a starting point.
You say "I have another VM which acts as a client", so I'll assume that you have a single client VM with multiple IP addresses. In this case I believe you can tell the Python socket module to bind to a specific network interface when sending. See this answer for details https://stackoverflow.com/a/335662/66349
This answer explicitly demonstrates its use: https://stackoverflow.com/a/8437870/66349
# from socket.h
# define SO_BINDTODEVICE 25
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, 25, 'eth0')
Here is an example of calling socket.setsockopt
in conjunction with urllib2: https://stackoverflow.com/a/17882197/66349
You might be able to piece those together into a functioning program.
来源:https://stackoverflow.com/questions/26055890/http-requests-using-a-range-of-ip-address-on-python