2012-04-04 2 views
0
내가 프록시 서버를 사용하여 HTTP 요청을 urllib2를 사용하고

파이썬 유사한 요청을하는 동안 내가 소스 인터페이스 IPADDRESS를 사용할 수있는 방법 컬 urllib2가 소스 인터페이스 주소

컬 --interface xx.xx.xx 말림 .XX -x yy.yy.yy.yy : 8080 www.google.com

#!/usr/bin/env python 

import urllib2 

proxy = urllib2.ProxyHandler({'http': 'xx.xx.xx.xx:8080'}) 
opener = urllib2.build_opener(proxy) 
urllib2.install_opener(opener) 
result = urllib2.urlopen('http://www.google.com') 

for line in result: 
    print line.rstrip("\n") 
+0

[파이썬 및 urllib2 소스 인터페이스] 가능한 복제본 (http://stackoverflow.com/questions/1150332/source-interface-with-python-and-urllib2) – bernie

답변

0

질문 may help you와 비슷한 대답이 있습니다. 당신은 API 스택에 깊은해야하고 어느 소스를 수정하거나 원숭이 코드를

import socket 
true_socket = socket.socket 
def bound_socket(*a, **k): 
    sock = true_socket(*a, **k) 
    sock.bind((sourceIP, 0)) 
    return sock 
socket.socket = bound_socket 

I 패치 것이다, 그래서이 여기에 답을 붙여 넣기 할 필요는 없지만 기본적으로 API는 당신에게 어떤 후크를 제공하지 않습니다 나는 당신의 질문을 이해하기를 바랍니다.