使用python上的IP地址范围的HTTP请求 [英] HTTP Requests using a range of IP address on python

查看:190
本文介绍了使用python上的IP地址范围的HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台VM作为服务器,其IP地址为10.91.55.2.我有另一个VM,它充当IP地址在10.91.56.2 ...... 10.91.56.10范围内的客户端.我想编写一个脚本,该脚本将使用客户端上的所有这些IP地址将HTTP请求发送到服务器(10.91.55.2).我编写了一个脚本,仅使用物理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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆