Created
July 12, 2020 06:51
-
-
Save trishantpahwa/2e32dc83e18f6ed077e758dc64278a0c to your computer and use it in GitHub Desktop.
This file contains 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
# This is an alternative to ngrok. Provided you have a server that is exposed to internet traffic. Gives you a personal domain to reach your program. | |
import socket | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind(('0.0.0.0', 8080)) | |
s.listen(5) | |
while True: | |
conn, addr = s.accept() | |
data = conn.recv(4096).decode('UTF-8') | |
if data: | |
data = data.split('\r\n') | |
for d in data: | |
if d.__contains__('Host: '): | |
d = d.split(' ') | |
d[1] = '192.168.1.33:3000' | |
d = ' '.join(d) | |
data[1] = d | |
data = '\r\n'.join(data) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect(('192.168.1.33', 3000)) | |
sock.sendall(data.encode()) | |
reply = sock.recv(4096) | |
sock.close() | |
conn.sendall(reply) | |
conn.close() | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment