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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.