HTTP Requests using a range of IP address on python

落花浮王杯 提交于 2019-12-02 22:34:40

问题


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.



来源:https://stackoverflow.com/questions/26055890/http-requests-using-a-range-of-ip-address-on-python

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