开发者

Removing SOCKS 4/5 proxy

This question is sort of the opposite of this:

How can I use a SOCKS 4/5 proxy with urllib2?

Let's say I use a SOCKS 5 proxy using the method accepted in that question. How would I revert it back to 开发者_Python百科no proxy in the same process?

i.e start process use proxy .. remove proxy ...

Maybe there is a better way to use the proxy so that it's easier to remove it later?


Abra kadabra

import socks,socket,urllib2
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 8080)
temp = socket.socket
socket.socket = socks.socksocket  
print urllib2.urlopen('http://www.google.com').read() // Proxy
socket.socket=temp
print urllib2.urlopen('http://www.google.com').read() // No proxy
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜