You've already forked ddns-updater
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
30 lines
591 B
Go
30 lines
591 B
Go
package dns_resolver
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func ResolveHostname(host string, dns_resolver_ip string) net.IP {
|
|
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, network, dns_resolver_ip+":53")
|
|
},
|
|
}
|
|
|
|
ips, err := r.LookupHost(context.Background(), host)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Could not get IPs: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
return net.ParseIP(ips[len(ips)-1])
|
|
}
|