98 lines
2.3 KiB
Go
98 lines
2.3 KiB
Go
// This creates a simple hello world window
|
|
package main
|
|
|
|
import (
|
|
"net"
|
|
"strings"
|
|
// "git.wit.org/wit/gui"
|
|
)
|
|
|
|
var DEBUGNET bool = false
|
|
|
|
// this doesn't work
|
|
func watchNetworkInterfaces() {
|
|
// Get list of network interfaces
|
|
interfaces, _ := net.Interfaces()
|
|
|
|
// Set up a notification channel
|
|
notification := make(chan net.Interface)
|
|
|
|
log(DEBUGNET, "watchNet()")
|
|
// Start goroutine to watch for changes
|
|
go func() {
|
|
log(DEBUGNET, "watchNet() func")
|
|
for {
|
|
log(DEBUGNET, "forever loop start")
|
|
// Check for changes in each interface
|
|
for _, i := range interfaces {
|
|
log(DEBUGNET, "something on i =", i)
|
|
if status := i.Flags & net.FlagUp; status != 0 {
|
|
notification <- i
|
|
log(DEBUGNET, "something on i =", i)
|
|
}
|
|
}
|
|
log(DEBUGNET, "forever loop end")
|
|
}
|
|
}()
|
|
log()
|
|
log(true, "this is true")
|
|
log(false, "this is false")
|
|
sleep(10.3)
|
|
exit(0)
|
|
}
|
|
|
|
func IsIPv6(address string) bool {
|
|
return strings.Count(address, ":") >= 2
|
|
}
|
|
|
|
func IsReal(ip *net.IP) bool {
|
|
if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) {
|
|
log(DEBUGNET, "\t\tIP is Real = false")
|
|
return false
|
|
} else {
|
|
log(DEBUGNET, "\t\tIP is Real = true")
|
|
return true
|
|
}
|
|
}
|
|
|
|
func scanInterfaces() {
|
|
ifaces, _ := net.Interfaces()
|
|
log(DEBUGNET, SPEW, ifaces)
|
|
for _, i := range ifaces {
|
|
addrs, _ := i.Addrs()
|
|
// log("range ifaces = ", i)
|
|
log("*net.Interface.Name = ", i.Name)
|
|
log(SPEW, i)
|
|
log(DEBUGNET, SPEW, addrs)
|
|
for _, addr := range addrs {
|
|
log(DEBUGNET, "\taddr =", addr)
|
|
log(DEBUGNET, SPEW, addrs)
|
|
ips, _ := net.LookupIP(addr.String())
|
|
log(DEBUGNET, "\tLookupIP(addr) =", ips)
|
|
switch v := addr.(type) {
|
|
case *net.IPNet:
|
|
log(DEBUGNET, "\t\taddr.(type) = *net.IPNet")
|
|
log(DEBUGNET, "\t\taddr.(type) =", v)
|
|
ip := v.IP
|
|
log(DEBUGNET, "\t\taddr.IP =", ip)
|
|
if (IsIPv6(ip.String())) {
|
|
log(DEBUGNET, "\t\tIP is IPv6")
|
|
} else {
|
|
log(DEBUGNET, "\t\tIP is IPv4")
|
|
}
|
|
if (IsReal(&ip)) {
|
|
log("\tIP is Real ", addr)
|
|
} else {
|
|
log("\tIP is not Real", addr)
|
|
}
|
|
log(DEBUGNET, "\t\tIP is IsPrivate() =", ip.IsPrivate())
|
|
log(DEBUGNET, "\t\tIP is IsLoopback() =", ip.IsLoopback())
|
|
log(DEBUGNET, "\t\tIP is IsLinkLocalUnicast() =", ip.IsLinkLocalUnicast())
|
|
// log("\t\tIP is () =", ip.())
|
|
default:
|
|
log(DEBUGNET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v)
|
|
}
|
|
}
|
|
}
|
|
}
|