Cannot connect to python -m SimpleHTTPServer server - python

this this probably a very simple question, but I haven't been able to find an answer anywhere. On the online articles about it, they didn't show the exact process to share a directory using SimpleHTTPServer. I've run the command successfully and have the server running, but I can only access it on the machine that started it.
192.168.1.2:8000
I've tried it on a Windows machine and iPad (although that doesn't really make a difference) on the local network. To access it, I've been using my local IP address, which I found by running ifconfig | grep inet, which returns (among other matches):
inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255
And after searching a bit online, I found: https://github.com/shbhrsaha/instant-sharing/blob/master/share.py.
There's function which supposedly gives you a handy url to share with your friends, but I tried running locally, and all I got was "localhost.localdomain", which obviously returns 127.0.0.1
How can I make this work?

When you start SimpleHTTPServer it tells which IP addresses it is listening to:
python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
Address 0.0.0.0 means it listening to all available IP addresses. Thus in this case you should simply reach the server by going http://192.168.1.two:8000
If it doesn't work then it is most likely a network issue. You can test this out with telnet command (both Windows and UNIX available): telnet will open a TCP/IP connection on a certain IP and certain port.
E.g. on UNIX you can do:
telnet 192.168.1.2 8000
If you get:
telnet 192.162.1.2 8000
Trying 192.162.1.2...
telnet: connect to address 192.162.1.2: Connection refused
telnet: Unable to connect to remote host
... it means SimpleHTTPServer is running.
If it waits for very long time it means your router/firewall is blocking the connection.
If you get a reply:
telnet localhost 8000
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
... browser should work as well. You can quit telnet by just keep hitting the enter (the SimpleHTTPServer will close the connection).

In Ubuntu
I had the same problem, then I narrowed it down to be a firewall problem.
First, check if your firewall is active.
sudo ufw status
If it is active by default it blocks all incoming connections from anywhere.
You can check whether you have granted access to your running port. The following command will list down all the available rules. if your port is not there with access given to other ports then you need to grant access.
sudo ufw status numbered
[This is what the issue] Now grant access on the port for desired ip addresses/ all. I allowed all incoming connections to the port 8000 on all ip adress by following command.
sudo ufw allow from any to any port 8000 proto udp
Initially, I thought this should be tcp instead of udp but worked with udp only. Something to dig up later.

The server was running, and we could access it, but only on the server's machine.
There was something blocking the connection, and that was The Firewall.
We configured The Firewall and it worked fine, my other device could get access.

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 ZeroRPC heartbeat error on public IP

I run a ZeroRPC server and I can connect successfully with a client to the 127.0.0.1 IP.
However when I use the public IP of the server to the client I get the following error:
zerorpc.exceptions.LostRemote: Lost remote after 10s heartbeat
I have opened the port from the firewall (using ufw on Ubuntu) but still get the same error.
Do you have any ideas what the problem might be?
Thanks!!
What IP address are you binding the server onto? If you want to listen on all interfaces and all addresses, something like tcp://0.0.0.0:4242 should work.

Setting up a Django development server that can be accessed by other devices on my network

I want to set up a Django development server that both my computers and smart phones can access whilst on my network via wifi.
I've already set up a development server that my computer can access on http://127.0.0.1:8000/. However, my other devices can't.
The Django documentation says:
"Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. To make your development server viewable to other machines on the network, use its own IP address (e.g. 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled)."
I've found my "public IP address" and tried to use this by:
python manage.py runserver xx.xx.xxx.x (where this is my public ip address) but i get a "Command error: 'xx.xx.xxx.x' is not a valid port number or address:port pair."
I then tried the same with :8000 after the IP address, but got an error "Error: That IP address can't be assigned to".
Then python manage.py runserver 0.0.0.0:8000. The command line reports "Starting development server at ...", but when i try "http://0.0.0.0:8000/" on Chrome, i get a "This site can't be reached error".
Is it something to do with my windows firewall settings?
Please can you someone help me? Thanks!
This is very late, but I run onto an additional issue following this post. If you are using a rhel distro based and if firewalld
is enabled it might be blocking the connection. So for testing purposes run:
systemctl stop firewalld
0.0.0.0 is not a real address, it's a placeholder that just says that the server is not bound to a specific IP.
If you run on 127.0.0.1, it will only answer to queries that where addressed to 127.0.0.1, so localhost only.
Using your private address (192.168.0.x most often), it will only answer to queries to this address (so opening with the 127.0.0.1 should not work, but sometime does depending on the implementation)
So, if you use 0.0.0.0, it will answer to anything.
tl;dr : use 0.0.0.0 and connect using :
127.0.0.1 from this computer
your computer's private ip address for other computers inside your lan
you public IP for computers outside your lan. Note that this will require additional configuration on your router
You will need your local ip address not public.
You can get the local ip in windows machine by typing the following command in cmd : ipconfig .
On Linux type the following in terminal : ifconfig
The ip address will be of the form 192.168.0.101[Example]
So in your phone's browser type : 192.168.0.101:8000

Docker Mac Beta and container connecting to host ports?

I currently use PyCharm (Actually IntelliJ) and have been using Kitematic with VirtualBox support.
I have a container connecting to the host (which is a virtual machine) to do remote debugging.
The issue is when I try to use Docker Mac Beta, the container doesn't seem to be able to access any specific ports on the host but it can ping the host. Which doesn't make any sense...
Anyone have any ideas?
Is there some magic sauce I need to make the python debugger listen on all IPs/Ports maybe?
Edits:
To clarify, when running a python script in this environment, the script has to initiate an outbound connect to a specified ip/port.
Here's some console output to help understand:
This is inside the container itself. I have the debugger running on port 15001 on my Mac.
# /sbin/ip route|awk '/default/ { print $3 }'
172.17.0.1
# ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: icmp_seq=0 ttl=64 time=0.078 ms
64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.066 ms
^C--- 172.17.0.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.066/0.072/0.078/0.000 ms
# telnet 172.17.0.1 15001
Trying 172.17.0.1...
telnet: Unable to connect to remote host: Connection refused
#
And then on the host (my mac):
➜ telnet localhost 15001
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
501 1 0.1 UNIX
This all works fine with the old virtualbox based Docker setup, which makes sense since its using full fledge virtual machines. But not sure how the new Docker Beta works, especially when it comes to networking.
I am using Docker-Compose for this, so I can set up the networking through the network configuration options but so far, I haven't gotten any random attempts to work.
Also, the container is able to access anything else (google.com or whatever), just not a specific port on the host machine.
I think the problem is that you need to expose port 15001.
Try adding to Dockerfile
EXPOSE 15001
Create a host-based loopback device and then use a remote_host alternative (like in xdebug) to configure your container to connect back to that host ( on the port ), this will solve your issue as it does for PHP ( same issue ). We had the same case when switching from dockertoolbox to docker for mac. See a configuration example including the launchdaemon to create the host loopback interface here: https://gist.github.com/EugenMayer/3019516e5a3b3a01b6eac88190327e7c

Python LDAP Authentication from remote web server

I have a django application hosted on webfaction which now has a static/private ip.
Our network in the office is obviously behind a firewall and the AD server is running behind this firewall. From inside the network i can authenticate using python-ldap with the AD's internal IP address and the port 389 and all works well.
When i move this to the hosted webserver i change the ip address and port that has been openend up on our firewall. For simplicity the port we opened up is 389 however the requests to authenticate always timeout. When logged into webfaction and running python from the shell and querying the ipaddress i get webfactional's general ip address rather than my static ip.
Is this whats happening when i try and auth in django? the request comes from the underlying ip address that python is running on rather than the static ip that my firewall is expecting?
Im fairly clueless to all this networking and port mapping so any help would be much appreciated!
Hope that makes sense?
I would recommend against opening the port on the firewall directly to LDAP. Instead I would suggest making an SSH tunnel. This will put the necessary encryptionn around the LDAP traffic. Here is an example.
ssh -N -p 22 username#ldapserver -L 2222/localhost/389
This assumes that the ssh server is running on port 22 of your ldap server, and is accessible from your web host. It will create a tunnel from port 389 on the ldap server to port 2222 on the web host. Then, you configure your django application on the web host to think that the LDAP server is running on localhost port 2222.
There are quite a few components between your hosted django application and your internal AD. You will need to test each to see if everything in the pathways between them is correct.
So your AD server is sitting behind your firewall. Your firewall has ip "a.b.c.d" and all traffic to the firewall ip on port 389 is forwarded to the AD server. I would recommend that you change this to a higher more random port on your firewall, btw. Less scans there.
With the shell access you can test to see if you can reach your network. Have your firewall admin check the firewall logs while you try one of the following (or something similar with python) :
check the route to your firewall (this might not work if webfaction blocks this, otherwise you will see a list of hosts along which your traffic will pass - if there is a firewall on the route somewhere you will see that your connection is lost there as this is dropped by default on most firewalls):
tracert a.b.c.d
do a telnet to your firewall ip on port 389 (the telnet test will allow your firewall admin to see the connection attempts coming in on port 389 in his log. If those do arrive, that means that external comm should work fine):
telnet a.b.c.d 389
Similarly, you need to check that your AD server receives these requests (check your logs) and as well can respond to them. Perhaps your AD server is not set up to talk to the firewall ?

Categories