0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

use google for lookup

This commit is contained in:
Zack Scholl 2020-11-17 10:29:52 -08:00
parent b740e491e6
commit dbc4a08ad0

View file

@ -1,6 +1,11 @@
package models package models
import "net" import (
"context"
"fmt"
"net"
"time"
)
// TCP_BUFFER_SIZE is the maximum packet size // TCP_BUFFER_SIZE is the maximum packet size
const TCP_BUFFER_SIZE = 1024 * 64 const TCP_BUFFER_SIZE = 1024 * 64
@ -14,12 +19,35 @@ var (
) )
func init() { func init() {
iprecords, _ := net.LookupIP(DEFAULT_RELAY) DEFAULT_RELAY, _ = lookupIP(DEFAULT_RELAY)
for _, ip := range iprecords { DEFAULT_RELAY += ":" + DEFAULT_PORT
DEFAULT_RELAY = ip.String() + ":" + DEFAULT_PORT DEFAULT_RELAY6, _ = lookupIP(DEFAULT_RELAY6)
DEFAULT_RELAY6 += "[" + DEFAULT_RELAY6 + "]:" + DEFAULT_PORT
// iprecords, _ := lookupIP(DEFAULT_RELAY)
// for _, ip := range iprecords {
// DEFAULT_RELAY = ip.String() + ":" + DEFAULT_PORT
// }
// iprecords, _ = lookupIP(DEFAULT_RELAY6)
// for _, ip := range iprecords {
// DEFAULT_RELAY6 = "[" + ip.String() + "]:" + DEFAULT_PORT
// }
} }
iprecords, _ = net.LookupIP(DEFAULT_RELAY6)
for _, ip := range iprecords { func lookupIP(address string) (ipaddress string, err error) {
DEFAULT_RELAY6 = "[" + ip.String() + "]:" + DEFAULT_PORT r := &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{
Timeout: time.Millisecond * time.Duration(10000),
} }
return d.DialContext(ctx, "udp", "8.8.8.8:53")
},
}
ip, err := r.LookupHost(context.Background(), address)
if err != nil {
fmt.Println(err)
return
}
ipaddress = ip[0]
return
} }