27 April 2012

Starting a Dead-Simple Webserver Using Python

technology.pngI ran across this post, which pointed out that the popular programming language Python has a built-in webserver.
It's definitely not for anything like production use, but if you just want to share a few files over your home network, it's great.   And because it's Python, it should run pretty much the same no matter what operating system you have Python installed on.


PLEASE NOTE:  CONFIGURE YOUR ROUTER AND COMPUTER FIREWALLS BEFORE LEAVING ANYTHING LIKE THIS RUNNING.


The command is pretty simple - from a command prompt, type:
python -m SimpleHTTPServer

and you'll be up and running.  Point the browser at your computer's local IP address (find it on Windows, Mac, Linux) and port 8000.  So let's say your computer is at 192.168.1.1.  In the browser bar, you type
http://192.168.1.1:8000
and boom!
Of course, me being me, this wasn't enough.  So I made two bash scripts - one to call from a terminal window (like, from an alias), and one to call using Zenity so I could choose the directory.  They should also be embedded below; YMMV with those. While Zenity is cross-platform, bash isn't.
With convention season coming up, this is an interesting alternative to carrying around thumbdrives, don't you think?  Just remember to shut down the server when you're not actively using it.
Terminal script:

Zenity GUI script:

Post a Comment