Is it possible to run python SimpleHTTPServer on localhost only?

后端 未结 3 1628
终归单人心
终归单人心 2020-12-02 06:07

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

3条回答
  •  不知归路
    2020-12-02 07:00

    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.

提交回复
热议问题