Python reverse proxy connection - python

I'm trying to make a HTTP/S proxy server work without having to manually port forward.
Machine A has installed a proxy server
Machine A is behind a NAT (or a router with firewall).
Machine B tries to browse internet through Machine A proxy.
Machine B isn't behind a NAT.
Both machines know each other before any connection is made.
In a full scale, there would be multiple Machine A but only one Machine B.
Machine A shouldn't need to configure anything on the router.
I have thought about using uPnP, as per this answer, but as the title of this question, I wanted to know if it would be possible to invert the roles of the machines.
Instead of Machine B initiating a connection, Machine A will do it. So Machine A would be the client and Machine B would be the server. Remember Machine A knows the IP address of Machine B beforehand.
In this scenario, Machine A would still function as a proxy, but having the role of the client in a standard TCP connection.
I understand this would need a custom-made proxy server, which is no problem since the proxy server is implemented in python and I have access to the source, and can modify it.
Will this be compatible with normal HTTP/S proxy? Specifically I will be using python requests on Machine B.
Does this method have a name? Researching for inverse or reverse lands me on reverse proxy which AFAIK doesn't have anything to do with what I'm trying to accomplish.
Is there something I'm missing? Or an alternative solution? (besides uPnP)

a simple solution is OpenSSH port forwarding.
first forward port 20000 on "Machine B" to port 10000 on "Machine A" with remote port forwarding:
[A]$ ssh -N -R 20000:localhost:10000 Machine_B
then setup a tunnel on port 10000 on "Machine A" with dynamic port forwarding:
[A]$ ssh -N -D 10000 localhost
now you can use 127.0.0.1:20000 as a SOCKS5 proxy on "Machine B":
[B]$ curl --socks5 127.0.0.1:20000 example.com

it called "Reverse", you need shootback to reverse TCP tunnel, it work like OpenSSH port forwarding and Socks5 proxy server like pysocks it better than HTTP/S proxy server.
on MachineB (You)
python3 master.py -m 0.0.0.0:10000 -c 0.0.0.0:10800
on MachineA (Remote)
python socks5.py start --port=1080
python slaver.py -m <MachineA_IP>:10000 -t 127.0.0.1:1080
now on MachineB you can set browser or any app to socks5
localhost:10800

Related

How do I access a python http server from a remote connection?

I'm trying out the command python http.server from the command line, and am trying to access the server. I can access easily from localhost, but whenever I try to use a remote connection, I am unable to connect.
I've tried different ports, and it doesn't look like my firewall is blocking any connections.
From the command line, I run
python3 -m http.server 8000
which returns
Serving HTTP on 0.0.0.0 port 8000 ...
However, I can only connect to the server from localhost.
sudo iptables -S
returns the following:
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
I expect to be able to connect from a remote host with the url http://10.247.30.125:8000 (my ip address), but I am unable to do so. The same url works fine on localhost.
I figured out what was going on. Did some reading about IP and NAT, and noticed that any ip address beginning with a 10 is reserved for private ip addresses. So, trying to connect to 10.247.30.125:8000 from anywhere other than my own network (so while not connected to my wifi) doesn't work. To be able to connect from an external network, I would need to set up port forwarding (like Reedinationer suggested), and I would need to use my router's public IP address rather than my computer's private IP address. I would set up a port forward from my router to direct external traffic to my computer, which would allow me to connect to my personal computer from an external network.
Thanks to everyone who responded!
port is missing from the url try this url it should work "http://10.247.30.125:8000"

python request remote web server via CLI through a ssh tunnel?

I installed a web server on a remote machine that can be only access through a ssh tunnel. Therefore, I have run with putty a ssh tunnel by specifying a port forwarding (in my case 8159). I have also configured the socks proxy on my browser to access to my remote webserver. Futhermore, with a curl command I can get the webpages if I add the following option --sock5-hostname localhost:8159.
Now, I would like to use python to request those webpages by passing through the ssh tunnel that I have configured with putty. I tried pysocks and proxy environment variables in my python code but it did not work. I would like to know if you have an idea to solve this problem.
Thank you in advance.

How to host flower on a remote machine that can also be accessed over the internet

I am trying to run flower on a remote ubuntu server. However, I am unsure on what address/port to run it on so that other people can login (I have the basic auth set up) and check their celery workers. The ubuntu server is actually an EC2 instance, so am I supposed to use its private or public ip address? Do I just open any standard port? In their docs, they use their example setup with http://localhost/5555 but I do not think that will work if flower will be running on a remote server. Any advice?
Flower runs on 5555 by default- which port are you running it on? The private IP is only available if the requests are coming from INSIDE your amazon network, so probably public.
So, if my guesses are right, you want to create an AWS security rule allowing traffic from "anywhere" to port 5555 and apply that to your instance, and then access that instance using its public ip like
http://50.31.10.99:5555

Cannot set up local server using external IP

I'm trying to set up two servers on my laptop using the script in https://github.com/misheska/foundations-of-python-network-programming/blob/master/python2/02/udp_remote.py.
As far as I understand, I can set a server just by typing
$ python udp_remote.py server
I want to start another server using my external IP, that I get using:
$ wget -q -O - http://myexternalip.com/raw
XXX.XXX.XXX.XXX
Then the server should be set with
$ python udp_remote.py server XXX.XXX.XXX.XXX
right???
Your syntax is correct (other than your IP4s being only 3 bytes long), but there are a couple reasons why you're having trouble:
It's not possible to bind to the same port twice on the same interface. Because the script has a fixed port number, you won't be able to run more than one instance unless your laptop has multiple interfaces.
Your WAN IP address will only be resolvable to an interface if your laptop itself is actually assigned that address. If the laptop is connected to a router and is assigned a local address, you won't be able to use the WAN address to specify the interface.
You cannot bind to an IP address that is not bound to an interface on the computer. If you require port forwarding to be set up on a router then consult your network administrator.

Quick issue with Python 3.1 http server

I'm have an issue with running the built in Python server that comes with 3.1, this may or may not be an issue with Python, in fact it probably isn't.
I start my server in the correct directory with "python -m http.server 8000" as the documentation suggests (http://docs.python.org/release/3.1.3/library/http.server.html).
When I navigate to that port on my local network with another computer using the url 192.168.2.104:8000 (my local ip and the port) my page loads. When I use my global IP, however, it stops working. Port 8000 is forwarded correctly. I used www.yougetsignal.com to verify that port 8000 was open using my global IP. Why in the world would Chrome be saying "Oops! Google Chrome could not connect to [REDACTED]:8000" then? Other server applications (such as my Minecraft server) work just fine. Is there something I'm missing? Furthermore, why would yougetsignal connect to my port but not Chrome?
With most routers ports are only mapped when someone connects from the outside (internet/WAN). You're testing it from your LAN so basically you're connecting to your router when you use your public IP. Ask a friend to test, i.e. from an outside connection.

Categories