14

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?

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
Student Loans
  • 303
  • 1
  • 4
  • 10

3 Answers3

13

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).

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • Provided the `telnet` result is the latter but one can still not access the server from another device, what would the diagnosis be? I am trying to access the `SimpleHTTPServer` running on my MBP on port 8000 from an iPad on the same Network. – oarfish May 22 '15 at 10:45
  • 1
    If the telnet works but browser doesn't work then it means that the network connection is fine, but the browser is not fine. Usually this means that the browser is trying to use a proxy server (ISP provided) for local network. The suggestion is to try with a different browser and check your browser proxy settings. – Mikko Ohtamaa May 22 '15 at 12:25
4

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.

Gayan Kavirathne
  • 2,909
  • 2
  • 18
  • 26
  • 1
    Hey Gayan, it's a small world. :) This helped. However, the above exact command didn't work for me. `sudo ufw allow 8000` worked. -Bhathiya – Bee Feb 05 '22 at 16:42
  • @Bee In my case I had to make sure it's udp. Default command would allow tcp. Dont know why SimpleHTTPServer started on udp for me. Maybe due to something else I configured somewhere. – Gayan Kavirathne Apr 21 '22 at 18:00
1

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.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Ilyasofficial
  • 23
  • 1
  • 6