如何使用ipv6 https代理连接到网站

问题描述 投票:0回答:1
import requests
import socket
from unittest.mock import patch


orig_getaddrinfo = socket.getaddrinfo
def getaddrinfoIPv6(host, port, family=0, type=0, proto=0, flags=0):
    return orig_getaddrinfo(host=host, port=port, family=socket.AF_INET6, type=type, proto=proto, flags=flags)

with patch('socket.getaddrinfo', side_effect=getaddrinfoIPv6):
    r = requests.get('http://icanhazip.com')
    print(r.text)

我想使用ipv6 https代理连接,而不是使用ipv4代理连接到网站。我已经搜索谷歌的答案,并没有找到任何(我明白)...最近我发现是...(不使用ipv6代理,而是使用我自己的ipv6)。我愿意使用除了请求之外的东西,但是,请求是首选。我稍后会尝试编写。

python proxy ipv6
1个回答
0
投票
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning


requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


proxy = {"http":"http://username:password@[2604:0180:2:3b5:9ebc:64e9:166c:d9f9]", "https":"https://username:password@[2604:0180:2:3b5:9ebc:64e9:166c:d9f9]"}

url = "https://icanhazip.com"

r = requests.get(url, proxies=proxy, verify=False)

print(r.content)

如果上面的代码不起作用

import requests

proxy = {"http": "http://userame:[email protected]:18117", "https":"https://userame:[email protected]:18117"}

url = "https://icanhazip.com"

r = requests.get(url, proxies=proxy)

print(r.content)

这是我目前的ipv6 https代理提供商,但是,他们使用ipv6 over ipv4到他们的客户端,所以这就是为什么这个代码有效,而上面的代码没有(如果使用相同的提供者)如果你使用的提供商单独支持ipv6,然后顶部的代码应该适合你。

© www.soinside.com 2019 - 2024. All rights reserved.