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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.