在 python 上使用 IP 地址范围的 HTTP 请求 [英] HTTP Requests using a range of IP address on python
问题描述
我有一个虚拟机作为服务器,IP 地址为 10.91.55.2.我有另一个虚拟机,它充当 IP 地址在 10.91.56.2......10.91.56.10 范围内的客户端.我想编写一个脚本,该脚本将使用客户端上的所有这些 IP 地址向服务器(10.91.55.2)发送 HTTP 请求.我编写了一个单独使用物理 IP 地址发送 HTTP 请求的脚本.有没有办法从 IP 地址范围发送 HTTP 请求.我的操作系统是 linux.
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.
您说我有另一个充当客户端的 VM",因此我假设您有一个具有多个 IP 地址的客户端 VM.在这种情况下,我相信您可以告诉 Python socket 模块绑定到发送时的特定网络接口.有关详细信息,请参阅此答案https://stackoverflow.com/a/335662/66349
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
这个答案明确展示了它的用途:https://stackoverflow.com/a/8437870/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')
以下是结合 urllib2 调用 socket.setsockopt
的示例:https://stackoverflow.com/a/17882197/66349
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.
这篇关于在 python 上使用 IP 地址范围的 HTTP 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!