这是我的代码:
try:
r = requests.head(url='http://'+finalURL, headers=headers, timeout=timeout, allow_redirects=True)
try:
print('Status', r.status_code)
print('Headers', r.headers)
print('Elapsed Total', r.elapsed.total_seconds())
except NameError as e:
print("Undefined variable", e)
我已经尝试过这个:print(r.raw._original_response.peer)
,正如我在此处的另一个答案中看到的那样,但它不起作用。
另一个选项是stream=True
,但在这种情况下Timeout
将不起作用,这就是我在某处读到的内容。
如何获取 IP 和端口?
最佳答案
如果stream=True
可接受:
response=requests.head('https://stackoverflow.com/questions/58149424/catch-the-ip-and-port-from-a-head-request',stream=True)
print response.raw._connection.sock.getpeername()
('151.101.129.69', 443)
关于python - 从 Head 请求中捕获 IP 和端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58149424/