Skip to content

Instantly share code, notes, and snippets.

@sansumbrella
Last active December 20, 2015 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sansumbrella/6213010 to your computer and use it in GitHub Desktop.
Save sansumbrella/6213010 to your computer and use it in GitHub Desktop.
Script to start a local server in the current directory. Basically a fancy SimpleHTTPServer, in that it's accessible by other devices on your LAN and it prints out the server address on startup.
#! /usr/bin/python
# Server config: http://stackoverflow.com/questions/4139170/bind-httserver-to-local-ipport-so-that-others-in-lan-can-see-it
# IP address: http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
import socket
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
# Announce the IP address and port we will serve on
port = 8000
print("Serving on %s:%s") % (socket.gethostbyname(socket.getfqdn()), port)
# Start a server to accept traffic
addr = ("0.0.0.0", port)
server = BaseHTTPServer.HTTPServer(addr, SimpleHTTPRequestHandler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment