The Python standard library provides a module called SimpleHTTPServer.py
which can be used to setup a
simple server on your local device.
Here is a brief description of how to have fun with it:
As simple as:
$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...
The setup server we have setup will listen to all the requests through the localhost
or 127.0.0.1
on the local system thorugh the port 8000
. This server looks for an index.html
file in the current working directory. If such a file does not, then it serves the file system i.e all the files and directories in the current path hierarchy.
However, this is of limited use as accessing files on the same system through the browser is no fun and of no practical utility. What we are interested in is serving the desired files on our local network, isn't it ? Sharing cool stuff with friends before deploying or sharing with the world.
Assuming you are working behind a private network i.e connected to internet through LAN, WiFi or a proxy server (in companies), you can share your data with systems connected in the same network by sharing your private IP address with the intended person.
For Linux/MacOSX(or *NIX systems):
$ ifconfig
For Windows:
$ ipconfig
There are a few hacky shell scripts to help you with this. However, these hacks are susceptible to change in OS internals.
For example, on MacOSX, en0
has been set as the name for the default device for wireless connections in favour of the earlier en1
. Hence, I am in favour of manually sorting through the list of active connections.
Note:
- `127.0.0.1` is the address of your localhost which is used for tasks involving your machine only.
- Your private IP address is a IPV4 number between:
- 10.0.0.0 - 10.255.255.255
- 172.16.0.0 - 172.31.255.255
- 192.168.0.0 - 192.168.255.255
On the other device, open up a browser and connect with http://<your_private_ip_address>:8000
.
Viola ! You will be greeted with either the index.html
or the file directory.
Press Ctrl + C
to shut down the server on the host machine and thus close the communication between the devices.
Happy networking !
Is there a way to hook this up between networks using my public IP address? I tried inputting it into my code where I usually put my private IP. Using
http.server
.Code: