Python's SimpleHTTPServer is very useful to run a local webserver.
But is it possible to configure a simple Python server so that only clients on the local machine can access it? (I'm thinking for local admin tools with a browser-based UI etc.)
Python's SimpleHTTPServer is very useful to run a local webserver.
But is it possible to configure a simple Python server so that only clients on the local machine can access it? (I'm thinking for local admin tools with a browser-based UI etc.)
You can open the server socket at the local loopback address 127.0.0.1. Then only clients from the same machine can access the server.
With an example from the SimpleHTTPServer docs.
import SimpleHTTPServer
import SocketServer
HOST = "127.0.0.1"
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer((HOST, PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
The question has been answered here as well.