1

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.)

interstar
  • 26,048
  • 36
  • 112
  • 180
  • You have to customize server. Here is help. http://stackoverflow.com/questions/4287019/stuck-with-python-http-server-with-basic-authentication-using-basehttp – Stephen Lin Jul 24 '14 at 06:22

1 Answers1

2

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.

Community
  • 1
  • 1
Djings
  • 56
  • 1
  • 5