Is it possible to run python SimpleHTTPServer on localhost only?

后端 未结 3 1609
终归单人心
终归单人心 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:04

    As @sberry explained, simply doing it by using the nice python -m ... method won't be possible, because the IP address is hardcoded in the implementation of the BaseHttpServer.test function.

    A way of doing it from the command line without writing code to a file first would be

    python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer(("127.0.0.1", 8888), shs.SimpleHTTPRequestHandler).serve_forever()'
    

    If that still counts as a one liner depends on your terminal width ;-) It's certainly not very easy to remember.

提交回复
热议问题