发出请求时如何利用ipv6地址块

时间:2018-11-09 06:48:30

标签: http go ipv6

大家好:我将如何配置http.transport以使用不同的ipv6地址来发出http请求(临时代理)。 我尝试过的:

    localAddr, err := net.ResolveIPAddr("ip6", "{ipv6 address}")
if err != nil {
    panic(err)
}
localTCPAddr := net.TCPAddr{
    IP: localAddr.IP,
}

webclient := &http.Client{
    Transport: &http.Transport{
        Proxy: http.ProxyFromEnvironment,
        DialContext: (&net.Dialer{
            LocalAddr: &localTCPAddr,
            Timeout:   30 * time.Second,
            KeepAlive: 30 * time.Second,
            DualStack: true,
        }).DialContext,
        MaxIdleConns:          100,
        IdleConnTimeout:       90 * time.Second,
        TLSHandshakeTimeout:   10 * time.Second,
        ExpectContinueTimeout: 1 * time.Second,
    },
}

ipv6地址失败:

panic: Get https://myip.addr.space/: dial tcp [{localAddr}]:0->[{hostip?}]:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

我有两个主要问题。我该怎么办

  1. 找到我可以使用的可用ipv6地址范围
  2. 在golang中以编程方式使用它们来发出http请求(再次模仿代理)

我想我要问的是:我该如何复制:https://github.com/blechschmidt/freebind/blob/master/freebind.c

0 个答案:

没有答案