Cannot connect to python server -m SimpleHTTPServer

This is probably a very simple question, but I have not found an answer anywhere. In online articles about this, they did not show the exact process of directory sharing using SimpleHTTPServer. I successfully executed the command and started the server, but I can only access it on the machine that started it.

192.168.1.2:8000 

I tried this on a Windows machine and an iPad (although it really doesn't matter) on the local network. To access it, I used my local IP address, which I found by running ifconfig | grep inet 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 the web I found: https://github.com/shbhrsaha/instant-sharing/blob/master/share.py .

A function that supposedly gives you a convenient URL for sharing with friends, but I tried working locally, and all I got was "localhost.localdomain", which obviously returns 127.0.0.1

How can I do this job?

+5
source share
1 answer

When you start SimpleHTTPServer, it tells which IP addresses it is listening:

  python -m SimpleHTTPServer Serving HTTP on 0.0.0.0 port 8000 ... 

The address 0.0.0.0 means that it is listening on all available IP addresses. Thus, in this case, you just need to get to the server by going to http: //192.168.1.two: 8000

If this does not work, it is most likely a network problem. You can verify this with the telnet command (both Windows and UNIX available): telnet will open a TCP / IP connection at a specific IP address and port.

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

... that means SimpleHTTPServer is working.

If it waits a very long time, it means your router / firewall is blocking the connection.

If you get an answer:

 telnet localhost 8000 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 

... the browser should work. You can exit telnet, just keep pressing input (SimpleHTTPServer will close the connection).

+5
source

Source: https://habr.com/ru/post/1210522/


All Articles