从headreques获取IP和端口

2024-06-30 15:38:51 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码:

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和端口


Tags: truehttpurl密码statustimeoutrequestshead
1条回答
网友
1楼 · 发布于 2024-06-30 15:38:51

如果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)

相关问题 更多 >