【问题标题】:Writing a Python webserver that can only be accessed from a client on the same machine?编写只能从同一台机器上的客户端访问的 Python 网络服务器?
【发布时间】:2014-09-15 13:13:09
【问题描述】:

Python 的 SimpleHTTPServer 对于运行本地网络服务器非常有用。

但是是否可以配置一个简单的 Python 服务器,以便只有本地机器上的客户端可以访问它? (我正在考虑使用基于浏览器的 UI 等的本地管理工具。)

【问题讨论】:

标签: python localhost simplehttpserver


【解决方案1】:

您可以在本地环回地址 127.0.0.1 处打开服务器套接字。那么只有来自同一台机器的客户端才能访问服务器。

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

问题has been answered here as well.

【讨论】:

    猜你喜欢
    • 2014-10-05
    • 2023-03-21
    • 1970-01-01
    • 2020-07-06
    • 2017-06-01
    • 1970-01-01
    • 2013-11-26
    • 2023-03-18
    • 2019-05-20
    相关资源
    最近更新 更多