You could use the loopback interface. localhost
or 127.0.0.1
refers to the local address, bypasses the full networking stack, and is not accessible via the network. See wikipedia
Take the SimpleHTTPServer example.
import SimpleHTTPServer
import SocketServer
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
We can bind to a specific address, you could use the address assigned to your machine/interface, or in your case, the loopback device.
httpd = SocketServer.TCPServer(("127.0.0.1", PORT), Handler)
You can then access the server at http://127.0.0.1:8000/
or http://localhost:8000/
. The server will not be accessible using your machines assigned IP address, both from your local machine and via the network.
The following may provide additional information