// 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) } } log.Println("forever loop") } }() } 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: log.Println("inotifyNetworkInterfaceChanges() event err =", err) return err } } } func IsIPv6(address string) bool { return strings.Count(address, ":") >= 2 } func IsReal(ip *net.IP) bool { if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) { log.Println("\t\tIP is Real = false") return false } else { log.Println("\t\tIP is Real = true") return true } } 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") } if (IsReal(&ip)) { log.Println("\t\tIP is Real = true") } else { log.Println("\t\tIP is Real = false") } log.Println("\t\tIP is IsPrivate() =", ip.IsPrivate()) log.Println("\t\tIP is IsLoopback() =", ip.IsLoopback()) log.Println("\t\tIP is IsLinkLocalUnicast() =", ip.IsLinkLocalUnicast()) // log.Println("\t\tIP is () =", ip.()) default: log.Println("\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v) } } } }