Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can I use a SOCKS 4/5 proxy with urllib2 to download a web page?

like image 358
Mike Avatar asked Feb 23 '10 11:02

Mike


People also ask

What port does Socks proxy use?

Usually a socks server listens at one port which is by default port 1080. This is used by all socksified applications. To look only for one port facilitates management and monitoring of network traffic.

How do I open SOCKS5 proxy?

Click the Apple icon at the top left of the menu bar on your screen and select System Preferences. Select Network and then Proxies. Click the Advanced button to access the Network settings and navigate to the Proxies tab. Click the SOCKS Proxy checkbox and enter the host and port information.

Is a Socks proxy secure?

SOCKS5 is the improved and latest version of the SOCKS protocol, SOCKS5 proxy is more secure than SOCKS4 because it establishes a full TCP connection and it also uses SSH encrypted tunneling method to relay the traffic i.e. a user can set up an SSH tunnel to send their unencrypted data over a network through an ...


1 Answers

You can use SocksiPy module. Simply copy the file "socks.py" to your Python's lib/site-packages directory, and you're ready to go.

You must use socks before urllib2. (Try it pip install PySocks )

For example:

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

You can also try pycurl lib and tsocks, for more detail, click on here.

like image 87
panweizeng Avatar answered Sep 24 '22 15:09

panweizeng