授予访问权限以在python BaseHTTPRequestHandler中指定远程IP

时间:2015-04-07 11:36:33

标签: python http python-3.x server

我想在python http服务器(BaseHTTPRequestHandler)中访问特定的远程IP。

hostName = "192.168.1.96"
hostPort = 80

class MyServer(BaseHTTPRequestHandler):
    def do_GET(self):
        ip = self.client_address[0]
        print(ip)
        #50.62.117.99
        self.send_response(200)
        #print(self.client_address[0])
        if(self.client_address[0] == "50.62.117.99"):
            self.send_header("Content-type", "text/html")
            self.end_headers()
            self.wfile.write(bytes("success", "utf-8"))
        else:
            self.send_response(404)
            self.send_header("Content-type", "text/html")
            self.end_headers()
            self.wfile.write(bytes("Not Found", "utf-8"))


myServer = HTTPServer((hostName, hostPort), MyServer)
print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort))
print(time.asctime(), 'Login Facebook....')

服务器工作正常但即使从正确的IP访问

,它始终返回Not Found

0 个答案:

没有答案