我想在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