Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run python SimpleHTTPServer on localhost only?

I have a vpn connection and when I'm running python -m SimpleHTTPServer, it serves on 0.0.0.0:8000, which means it can be accessed via localhost and via my real ip. I don't want robots to scan me and interested that the server will be accessed only via localhost.

Is it possible?

python -m SimpleHTTPServer 127.0.0.1:8000  # doesn't work. 

Any other simple http server which can be executed instantly using the command line is also welcome.

like image 515
user1639431 Avatar asked Sep 04 '12 17:09

user1639431


People also ask

Is python HTTP server good for production?

Python docs claim, that "http. server is not recommended for production. It only implements basic security checks."

What does python SimpleHTTPServer do?

The SimpleHTTPServer module is a Python module that enables a developer to lay the foundation for developing a web server. However, as sysadmins, we can use the module to serve files from a directory. The module loads and serves any files within the directory on port 8000 by default.


1 Answers

In Python versions 3.4 and higher, the http.server module accepts a bind parameter.

According to the docs:

python -m http.server 8000

By default, server binds itself to all interfaces. The option -b/--bind specifies a specific address to which it should bind. For example, the following command causes the server to bind to localhost only:

python -m http.server 8000 --bind 127.0.0.1

New in version 3.4: --bind argument was introduced.

like image 185
Jet Blue Avatar answered Oct 05 '22 05:10

Jet Blue