I am testing some python functionalities as web server. Typed :
$ python -m SimpleHTTPServer 8080
...and setup port forwarding on router to this 8080. I can access via web with http://my.ip.adr.ess:8080/, whereas my.ip.adr.ess stands for my IP adress.
When I started my xampp server it is accessible with http://my.ip.adr.ess/ and no 8080 port is required for accessing.
What should I have to do to python server responds like that?
It means that xampp is running on port 80 which is default for http://. You need to run SimpleHTTPServer on that port too. More info about running SimpleHTTPServer on port 80.
Specify the port as 80 (default port for HTTP protocol).
python -m SimpleHTTPServer 80
You may need superuser permission in Unix to bind port 80 (under 1024).
sudo python -m SimpleHTTPServer 80
Related
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"
When I run:
python -m http.server
I see the message Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
When I navigate there in my browser I see "This site can’t be reached".
I am using:
Windows 10
Python 3.6
The unix-style console emulator cmder (build on top of ConEmu).
Any ideas about what the problem could be? I've tried specifying different ports but there is no change.
go to http://127.0.0.1:8000 ... 0.0.0.0 means any available interface ... it does not mean the literal ip 0.0.0.0
I've been hosting a localhost on my Mac with CSS, HTML, and JS. To do this i just navigate to my file with cd Desktop followed by cd filename , and then I do python -m SimpleHTTPServer 8000 to host my server on my localhost. I know that this only works for the person hosting the server, but I'd like to host it on my local network, so anyone that goes to localhost:8000 will see it. (I'm fine with it not being localhost:8000, in fact, I'd love a custom name.)
Thank you
-A
First of all, localhost is a "domain" name if you like. Most of the times it resolves to 127.0.0.1 which is the loopback ip address(e.g. points back to your computer).
I am going to assume you are using python 2.x
So here we go:
#!/usr/bin/env python
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
addr = ("0.0.0.0", 8000) #host to everyone
serv = BaseHTTPServer.HTTPServer(addr, SimpleHTTPRequestHandler)
serv.serve_forever()
Save that to a python script and run with:
python myfile.py
If you are using python 3 then go with :
python3 -m http.server --bind 0.0.0.0 8000
Now for someone else to access your server through your local network, you have to give them your machine's ip.
To do that run:
ifconfig |grep inet
You should get something alone the lines of:
inet 192.168.1.2 netmask 0xffffff00 etc etc
Now anyone on your local network can use your server by typing
192.168.1.2:8000
in their browsers
One easy way to expose localhost to other people is using ngrok, available via brew install ngrok or that link.
In your example above, running ngrok 8000 would allow other people to access the server you've got hosted. It's worth noting, obviously, that this isn't restricted to your local network!
Perhaps a better option (if all you're doing is hosting static HTML, CSS & JS) would be to set up a simple Apache instance. The default config should probably work just fine, and people could then access your page using your computer's local IP e.g 192.168.0.10:8000, or whatever port you set up.
EDIT: As the other answerer pointed out, SimpleHTTPServer will do everything Apache does... You just need to give people your machine's local IP!
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.
So I'm a Mac user. I have pretty much no experience with Linux. So when I wanted to host a temporary web server on my Raspberry Pi (running Debian-derived Raspbian), I was stuck.
I'm using sudo python -m SimpleHTTPServer in the terminal to host a local server on localhost, but I need to map it to mu public IP on port 80. On my MacBook I use Port Map, and that works fine. Is there some software or a command I can do to map this on my 'Pi?
Thanks a bunch!
Alex
I am working on Ubuntu and it will be the same on Debian.
$ python -m SimpleHTTPServer
This will work even without sudo as it serves on non-privileged port 8000
If you want to serve on port 80, you have to use sudo and you shall pass port number on command line:
$ sudo python -m SimpleHTTPServer 80
There is no need to forward this port, it is served already.
Warning: SimpleHTTPServer is not the most secure web server, be careful with exposing your computer to the public this way.
Port forwarding using rinetd
If you want to do real port forwarding, there is a service called rinetd. It is very easy to configure.