简体   繁体   English

相当于curl --python的python

[英]python equivalent for curl --interface

What is the python equivalent for following shell command: curl --interface 10.91.56.2 http:/10.91.55.3/file0.txt 以下shell命令的python等效项是什么:curl --interface 10.91.56.2 http:/10.91.55.3/file0.txt
???? ????

I am using CentOS6.5-Linux and I want to send http request from virtual IP addresses like eth0:0,eth0:1,eth0:2,etc simultaneously with eth0. 我正在使用CentOS6.5-Linux,我想同时从eth0:虚拟地址(如eth0:0,eth0:1,eth0:2等)发送http请求。 I am actually trying to make one traffic generator tool using python. 我实际上正在尝试使用python制作一个流量生成器工具。 I have been successful in sending multiple and concurrent http requests and now my next step is to send such requests from multiple ip addresses.I used following cURL command to send request from eth0:1 " curl--interface 10.91.56.2 http:/10.91.55.3/file0.txt" and I was successful in generating traffic from virtual eth0:1. 我已经成功发送了多个并发的http请求,现在我的下一步是从多个IP地址发送此类请求。我使用了以下cURL命令,从eth0:1发送请求。curl –interface 10.91.56.2 http:/10.91 .55.3 / file0.txt”,则我成功地从虚拟eth0:1生成了流量。 Can anyone guide me how to do this using python? 谁能指导我如何使用python做到这一点? 10.91.56.2 is my virtual eth0:1 IP interface and 10.91.55.3 is my server address... – 10.91.56.2是我的虚拟eth0:1 IP接口,而10.91.55.3是我的服务器地址... –

Python Urllib2 provides perfect platform for making any HTTP request. Python Urllib2为发出任何HTTP请求提供了理想的平台。 In your case you can use urlopen() function... 您可以使用urlopen()函数...

More about this libary can be found in the below link: 有关此库的更多信息,请参见以下链接:

how-to-use-urllib2-in-python 如何在urllib2-python中使用

For me, eth0's ip is 10.91.56.3 and eth0:1's ip is 10.91.56.4 so, to generate traffic using 10.91.56.4(eth0:1) 对我来说,eth0的ip是10.91.56.3,而eth0:1的ip是10.91.56.4,以便使用10.91.56.4(eth0:1)来生成流量

Followed answer by @AKX here @AKX在这里跟随答案

In above answer in 3rd class write your interface's ip instead of 127.0.0.1 eg in my case i did like this: 在第三类的以上答案中,写接口的ip而不是127.0.0.1,例如,在我的情况下,我这样做:

class BindableHTTPHandler(urllib2.HTTPHandler):
    def http_open(self, req):
        return self.do_open(BindableHTTPConnectionFactory('10.91.56.4'), req)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM