summaryrefslogtreecommitdiff
path: root/hostname.go
diff options
context:
space:
mode:
Diffstat (limited to 'hostname.go')
-rw-r--r--hostname.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/hostname.go b/hostname.go
new file mode 100644
index 0000000..4725d2c
--- /dev/null
+++ b/hostname.go
@@ -0,0 +1,45 @@
+// inspired from:
+// https://github.com/mactsouk/opensource.com.git
+// and
+// https://coderwall.com/p/wohavg/creating-a-simple-tcp-server-in-go
+
+package main
+
+// import "net"
+
+// will try to get this hosts FQDN
+import "github.com/Showmax/go-fqdn"
+
+// this is the king of dns libraries
+import "github.com/miekg/dns"
+
+// dnssec IPv6 socket library
+import "git.wit.org/jcarr/dnssecsocket"
+
+func getHostname() {
+ var err error
+ me.fqdn, err = fqdn.FqdnHostname()
+ if (err != nil) {
+ log("FQDN hostname error =", err)
+ exit()
+ return
+ }
+ log("FQDN hostname is", me.fqdn)
+
+ var aaaa []string
+ aaaa = getAAAA(me.fqdn)
+ log("AAAA =", aaaa)
+}
+
+func getAAAA(s string) []string {
+ // lookup the IP address from DNS
+ dnsRR := dnssecsocket.Dnstrace(s, "AAAA")
+ log(args.VerboseDNS, SPEW, dnsRR)
+ if (dnsRR == nil) {
+ return nil
+ }
+ ipaddr1 := dns.Field(dnsRR, 1)
+ ipaddr2 := dns.Field(dnsRR, 2)
+ log("ipaddr", ipaddr1, ipaddr2)
+ return []string{ipaddr1, ipaddr2}
+}