Skip to content

Instantly share code, notes, and snippets.

@davidlares
Created March 13, 2020 16:23
Show Gist options
  • Save davidlares/3c0af9ae8be43721c9185e4290e352a5 to your computer and use it in GitHub Desktop.
Save davidlares/3c0af9ae8be43721c9185e4290e352a5 to your computer and use it in GitHub Desktop.
Forwarding traffic through SOCKS server (HTTP protocol Proxy)
#!/usr/bin/python
import socks
import socket
from urllib.request import urlopen
if __name__ == "__main__":
# defining the SOCKS proxy and the host
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "localhost", 9050)
# performing an request
req = urlopen("http://api.ipify.org/")
# priting the API request
print("The REAL IP is %s" % req.read().decode('utf8'))
# redirecting from socket to socks (forwarding)
socket.socket = socks.socksocket
# perfomrming an request
req = urlopen("http://api.ipify.org/")
print("The SOCKS IP is: %s" % req.read().decode('utf8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment