mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 17:04:02 +03:00
Fix ipv6/ipv4 name resolution
This commit is contained in:
+17
-4
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -9,16 +10,28 @@ import (
|
||||
"github.com/juju/errors"
|
||||
)
|
||||
|
||||
const ifconfigAddress = "https://ifconfig.co/ip"
|
||||
|
||||
func getGlobalIPv4() (net.IP, error) {
|
||||
return fetchIP("https://v4.ifconfig.co/ip")
|
||||
return fetchIP("tcp4")
|
||||
}
|
||||
|
||||
func getGlobalIPv6() (net.IP, error) {
|
||||
return fetchIP("https://v6.ifconfig.co/ip")
|
||||
return fetchIP("tcp6")
|
||||
}
|
||||
|
||||
func fetchIP(url string) (net.IP, error) {
|
||||
resp, err := http.Get(url)
|
||||
func fetchIP(network string) (net.IP, error) {
|
||||
dialer := &net.Dialer{DualStack: false}
|
||||
client := &http.Client{
|
||||
Jar: nil,
|
||||
Transport: &http.Transport{
|
||||
DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
|
||||
return dialer.DialContext(ctx, network, addr)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := client.Get(ifconfigAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user