简体   繁体   English

如何在Python请求的请求标头中看到ip地址?

[英]How can I see ip address in request header in Python requests?

When I make request to a url, I believe the ip address of the client is sent to the server. 当我向网址发出请求时,我相信客户端的ip地址已发送到服务器。 And in that case the ip address must be present in request header, or am I wrong? 在那种情况下,IP地址必须出现在请求标头中,否则我错了吗?

So, I say 所以,我说

import requests    
resp = requests.get("http://localhost:8000/test")
print resp.request.headers

But I can't see any ip address when printing resp.request.headers, so how can I view the ip address of client. 但是在打印resp.request.headers时看不到任何IP地址,因此如何查看客户端的IP地址。 And if I can't see it as part of resp.request.headers, how does server get the ip address of the client if it isn't present in request header? 如果我看不到它是resp.request.headers的一部分,那么如果请求头中不存在服务器,服务器如何获取客户端的IP地址?

IP address is not set by client, it is part of the connection. IP地址不是由客户端设置的,它是连接的一部分。 Quote from here : 这里引用:

(remote address) is taken from the ip address that hits the http server and not in the request. (远程地址)来自点击http服务器的IP地址,而不是请求中的IP地址。 as if you are behind a proxy you would only see the ip of the proxy. 就像您在代理后面一样,您只会看到该代理的IP。 it doesnt touch the http header data 它不会碰到HTTP标头数据

A server gets a connection, natrually it also knows where it comes from. 服务器获得连接,自然地它也知道它来自哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM