1
manoon 2012-11-20 10:28:30 +08:00 1
socket proxy
|
2
mudone 2012-11-20 17:52:52 +08:00
cURL可以指定ip发起请求。
|
3
CoX 2012-11-20 18:11:57 +08:00
以前做过个小应用,用的是httplib2,稍作了下修改就能bind ip 了,不知道requests能不能直接bind ip
|
4
Livid MOD import requests
headers = {} headers['Host'] = 'www.example.com' requests.get('http://10.0.0.1/', headers=headers) |
5
BigZ 2012-11-20 18:35:01 +08:00
@Livid 你没有看懂lz意思,
lz,你只能修改路由表,让系统使用指定IP作为源址,用ip route 来改 简单的做法是,你先在本机取消一个ip的绑定,只留你想要的那个 或者你起一个nginx做代理,配置文件里面listen两个不同的ip,python使用这个代理去采集,反正都是本机,性能损失不大 |
7
bhuztez 2012-11-20 18:44:44 +08:00 1
SO_BINDTODEVICE 泪流满面啊
|
10
zbgzao 2012-11-20 19:57:48 +08:00 2
当然random_ip务必要改为外网IP
http://gist.github.com/4117504 |
12
kuaizi 2012-11-20 20:10:35 +08:00
|
14
ledzep2 2012-11-20 20:32:39 +08:00
bind正解
|
16
humiaozuzu 2012-11-21 01:48:55 +08:00 1
@Livid @zbgzao 你的绞尽脑汁就是copy的很辛苦吗? http://stackoverflow.com/a/1150408/492864
@liuxurong google: python set source ip 就有很多答案了 |
19
neildd 2012-12-05 11:08:40 +08:00
--- /usr/lib64/python2.4/httplib.py 2009-09-04 03:38:18.000000000 +0800
+++ /usr/lib64/python2.4/httplib.py 2010-07-06 18:07:18.000000000 +0800 @@ -156,6 +156,7 @@ # maximal amount of data to read at one time in _safe_read MAXAMOUNT = 1048576 +Local_BindIP = None class HTTPMessage(mimetools.Message): def addheader(self, key, value): @@ -621,6 +622,8 @@ af, socktype, proto, canonname, sa = res try: self.sock = socket.socket(af, socktype, proto) + if Local_BindIP is not None: + self.sock.bind((Local_BindIP,0)) if self.debuglevel > 0: print "connect: (%s, %s)" % (self.host, self.port) self.sock.connect(sa) |