debugging on fqdn
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
1b48bec90b
commit
468842e572
|
@ -1,3 +1,5 @@
|
||||||
|
This thing segfault'd with fqdn lookup on weird network errors when I was at the office on wifi
|
||||||
|
|
||||||
2019/06/01 21:11:47 connecting to ws://v000185.testing.com.customers.wprod.wit.com:9000/event
|
2019/06/01 21:11:47 connecting to ws://v000185.testing.com.customers.wprod.wit.com:9000/event
|
||||||
2019/06/01 21:11:47 fqdn.Get() = librem15.lab.wit.com
|
2019/06/01 21:11:47 fqdn.Get() = librem15.lab.wit.com
|
||||||
INFO[0000] *** error: read udp [2604:bbc0:1:22::f5d3:7f44]:50435->[2001:500:12::d0d]:53: i/o timeout
|
INFO[0000] *** error: read udp [2604:bbc0:1:22::f5d3:7f44]:50435->[2001:500:12::d0d]:53: i/o timeout
|
||||||
|
|
18
fqdn.go
18
fqdn.go
|
@ -1,30 +1,36 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import "net"
|
||||||
"net"
|
import "os"
|
||||||
"os"
|
import "strings"
|
||||||
"strings"
|
import "log"
|
||||||
)
|
|
||||||
|
|
||||||
// Get Fully Qualified Domain Name
|
// Get Fully Qualified Domain Name
|
||||||
// returns "unknown" or hostanme in case of error
|
// returns "unknown" or hostanme in case of error
|
||||||
func FqdnGet() string {
|
func fqdnGet() string {
|
||||||
|
log.Println("fqdnGet() START")
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("\tfqdnGet() net.LookupIP(hostname) hostname =", hostname)
|
||||||
addrs, err := net.LookupIP(hostname)
|
addrs, err := net.LookupIP(hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("\tfqdnGet() net.LookupIP(hostname) err =", err)
|
||||||
return hostname
|
return hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Println("\tfqdnGet() range addrs")
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
|
log.Println("\tfqdnGet() addr = ", addr)
|
||||||
if ipv4 := addr.To4(); ipv4 != nil {
|
if ipv4 := addr.To4(); ipv4 != nil {
|
||||||
ip, err := ipv4.MarshalText()
|
ip, err := ipv4.MarshalText()
|
||||||
|
log.Println("\tfqdnGet() ip = ", string(ip))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return hostname
|
return hostname
|
||||||
}
|
}
|
||||||
|
log.Println("\tfqdnGet() net.LookupAddr = ", string(ip))
|
||||||
hosts, err := net.LookupAddr(string(ip))
|
hosts, err := net.LookupAddr(string(ip))
|
||||||
if err != nil || len(hosts) == 0 {
|
if err != nil || len(hosts) == 0 {
|
||||||
return hostname
|
return hostname
|
||||||
|
|
4
main.go
4
main.go
|
@ -106,8 +106,8 @@ func main() {
|
||||||
// use this to discover what the OS thinks it's hostname is
|
// use this to discover what the OS thinks it's hostname is
|
||||||
// seems to be cross platform (?)
|
// seems to be cross platform (?)
|
||||||
// Windows: WMIC computersystem where caption='current_pc_name' rename new_pc_name
|
// Windows: WMIC computersystem where caption='current_pc_name' rename new_pc_name
|
||||||
hostname := FqdnGet()
|
hostname := fqdnGet()
|
||||||
log.Println("fqdn.Get() = ", hostname)
|
log.Println("fqdnGet() = ", hostname)
|
||||||
config.Hostname = hostname
|
config.Hostname = hostname
|
||||||
|
|
||||||
// this is a recursive dig for the AAAA record
|
// this is a recursive dig for the AAAA record
|
||||||
|
|
Loading…
Reference in New Issue