Created
March 13, 2020 16:23
-
-
Save davidlares/3c0af9ae8be43721c9185e4290e352a5 to your computer and use it in GitHub Desktop.
Forwarding traffic through SOCKS server (HTTP protocol Proxy)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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