From ea88b7049a47ba1da3807256399d14c3eb82b2b9 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 12 Feb 2023 15:35:56 -0600 Subject: [PATCH] add IsRealIP() and IsIPv6() Signed-off-by: Jeff Carr --- Makefile | 3 ++ gui.go | 2 + he-ipv6-tunnel.sh | 37 +++++++++++++++++ lookupAAAA.go | 32 +++++++++++++++ main.go | 67 +----------------------------- net.go | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 177 insertions(+), 65 deletions(-) create mode 100755 he-ipv6-tunnel.sh create mode 100644 lookupAAAA.go create mode 100644 net.go diff --git a/Makefile b/Makefile index cc323ec..2efe6cb 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ run: build + reset ./control-panel-dns build-release: @@ -21,3 +22,5 @@ deb: cd debian && make -wit mirrors +netlink: + GO111MODULE="off" go get -v -u github.com/vishvananda/netlink diff --git a/gui.go b/gui.go index 3f7c31a..71d7b7f 100644 --- a/gui.go +++ b/gui.go @@ -63,6 +63,8 @@ func addDNSTab(window *gui.Node, title string) { } g2.NewButton("hello", func () { log.Println("world") + }) + g2.NewButton("scanInterfaces()", func () { scanInterfaces() }) g2.NewButton("os.Hostname()", func () { diff --git a/he-ipv6-tunnel.sh b/he-ipv6-tunnel.sh new file mode 100755 index 0000000..e3a6877 --- /dev/null +++ b/he-ipv6-tunnel.sh @@ -0,0 +1,37 @@ +#!/bin/bash -x + +## Tunnel ID: 818143 +# Creation Date:Feb 12, 2023 +# Description: +# IPv6 Tunnel Endpoints +# Server IPv4 Address:184.105.253.14 +# Server IPv6 Address:2001:470:1f10:2a::1/64 +# Client IPv4 Address:74.87.91.117 +# Client IPv6 Address:2001:470:1f10:2a::2/64 +# Routed IPv6 Prefixes +# Routed /64:2001:470:1f11:2a::/64 +# Routed /48:Assign /48 +# DNS Resolvers +# Anycast IPv6 Caching Nameserver:2001:470:20::2 +# Anycast IPv4 Caching Nameserver:74.82.42.42 +# DNS over HTTPS / DNS over TLS:ordns.he.net +# rDNS DelegationsEdit +# rDNS Delegated NS1: +# rDNS Delegated NS2: +# rDNS Delegated NS3: +# rDNS Delegated NS4: +# rDNS Delegated NS5: + +# ifconfig sit0 up +# ifconfig sit0 inet6 tunnel ::184.105.253.14 +# ifconfig sit1 up +# ifconfig sit1 inet6 add 2001:470:1f10:2a::2/64 +# route -A inet6 add ::/0 dev sit1 + +modprobe ipv6 +ip tunnel add he-ipv6 mode sit remote 184.105.253.14 local 74.87.91.117 ttl 255 +ip link set he-ipv6 up +ip addr add 2001:470:1f10:2a::2/64 dev he-ipv6 +ip route add ::/0 dev he-ipv6 +ip -f inet6 addr + diff --git a/lookupAAAA.go b/lookupAAAA.go new file mode 100644 index 0000000..8ae3f02 --- /dev/null +++ b/lookupAAAA.go @@ -0,0 +1,32 @@ +package main + +/* +import "log" +import "github.com/miekg/dns" + +import "git.wit.org/jcarr/dnssecsocket" + +import "github.com/davecgh/go-spew/spew" +// import "github.com/Showmax/go-fqdn" + +func lookupAAAA(hostname string) string { + // lookup the IP address from DNS + dnsRR := dnssecsocket.Dnstrace(hostname, "AAAA") + spew.Dump(dnsRR) + if (dnsRR == nil) { + return "BROKEN" + } + ipaddr := dns.Field(dnsRR, 1) + log.Println("ipaddr", ipaddr) + return ipaddr +} +*/ + +/* +func main() { + hostname := "check.lab.wit.org" + // 2604:bbc0:2:248:5054:f0ff:fe00:156 + + lookupAAAA(hostname) +} +*/ diff --git a/main.go b/main.go index 1d4d4df..48bdd56 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,8 @@ package main import ( "log" - "net" - "github.com/fsnotify/fsnotify" + // "net" + // "github.com/fsnotify/fsnotify" "git.wit.org/wit/gui" arg "github.com/alexflint/go-arg" ) @@ -25,66 +25,3 @@ func main() { go inotifyNetworkInterfaceChanges() gui.Main(initGUI) } - -func watchNetworkInterfaces() { - // Get list of network interfaces - interfaces, _ := net.Interfaces() - - // Set up a notification channel - notification := make(chan net.Interface) - - // Start goroutine to watch for changes - go func() { - for { - // Check for changes in each interface - for _, i := range interfaces { - if status := i.Flags & net.FlagUp; status != 0 { - notification <- i - log.Println("something on i =", i) - } - } - } - }() -} - -func inotifyNetworkInterfaceChanges() error { - watcher, err := fsnotify.NewWatcher() - if err != nil { - return err - } - defer watcher.Close() - - // Watch for network interface changes - err = watcher.Add("/sys/class/net") - if err != nil { - return err - } - for { - select { - case event := <-watcher.Events: - log.Println("inotifyNetworkInterfaceChanges() event =", event) - if event.Op&fsnotify.Create == fsnotify.Create { - // Do something on network interface creation - } - case err := <-watcher.Errors: - return err - } - } -} - -func scanInterfaces() { - ifaces, _ := net.Interfaces() - for _, i := range ifaces { - log.Println(i) - addrs, _ := i.Addrs() - for _, addr := range addrs { - log.Println("\taddr =", addr) - switch v := addr.(type) { - case *net.IPNet: - log.Println("\t\taddr.(type) = *net.IPNet") - default: - log.Println("\t\taddr.(type) =", v) - } - } - } -} diff --git a/net.go b/net.go new file mode 100644 index 0000000..9c124bc --- /dev/null +++ b/net.go @@ -0,0 +1,101 @@ +// This creates a simple hello world window +package main + +import ( + "log" + "net" + "strings" + "github.com/fsnotify/fsnotify" + // "git.wit.org/wit/gui" + "github.com/davecgh/go-spew/spew" +) + +func watchNetworkInterfaces() { + // Get list of network interfaces + interfaces, _ := net.Interfaces() + + // Set up a notification channel + notification := make(chan net.Interface) + + // Start goroutine to watch for changes + go func() { + for { + // Check for changes in each interface + for _, i := range interfaces { + if status := i.Flags & net.FlagUp; status != 0 { + notification <- i + log.Println("something on i =", i) + } + } + } + }() +} + +func inotifyNetworkInterfaceChanges() error { + watcher, err := fsnotify.NewWatcher() + if err != nil { + return err + } + defer watcher.Close() + + // Watch for network interface changes + err = watcher.Add("/sys/class/net") + if err != nil { + return err + } + for { + select { + case event := <-watcher.Events: + log.Println("inotifyNetworkInterfaceChanges() event =", event) + if event.Op&fsnotify.Create == fsnotify.Create { + // Do something on network interface creation + } + case err := <-watcher.Errors: + return err + } + } +} + +func IsIPv6(address string) bool { + return strings.Count(address, ":") >= 2 +} + +func scanInterfaces() { + ifaces, _ := net.Interfaces() + spew.Dump(ifaces) + for _, i := range ifaces { + addrs, _ := i.Addrs() + log.Println("addrs = ", i) + spew.Dump(addrs) + for _, addr := range addrs { + log.Println("\taddr =", addr) + spew.Dump(addr) + ips, _ := net.LookupIP(addr.String()) + log.Println("\tLookupIP(addr) =", ips) + switch v := addr.(type) { + case *net.IPNet: + log.Println("\t\taddr.(type) = *net.IPNet") + log.Println("\t\taddr.(type) =", v) + ip := v.IP + // spew.Dump(ip) + log.Println("\t\taddr.IP =", ip) + if (IsIPv6(ip.String())) { + log.Println("\t\tIP is IPv6") + } else { + log.Println("\t\tIP is IPv4") + } + log.Println("\t\tIP is IsPrivate() =", ip.IsPrivate()) + log.Println("\t\tIP is IsLoopback() =", ip.IsLoopback()) + log.Println("\t\tIP is IsLinkLocalUnicast() =", ip.IsLinkLocalUnicast()) + if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) { + log.Println("\t\tIP is Real = false") + } else { + log.Println("\t\tIP is Real = true") + } + // log.Println("\t\tIP is () =", ip.()) + default: + log.Println("\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v) + } + } + } +}