HTTP Requests using a range of IP address on python

∥☆過路亽.° 提交于 2019-12-02 13:02:09
Peter Gibson

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!