2023-02-18 23:37:11 -06:00
|
|
|
// This creates a simple hello world window
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-12-20 03:13:43 -06:00
|
|
|
// "log"
|
2023-02-18 23:37:11 -06:00
|
|
|
"net"
|
|
|
|
"strings"
|
2024-01-03 12:40:31 -06:00
|
|
|
|
|
|
|
"go.wit.com/log"
|
2023-02-18 23:37:11 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// this doesn't work
|
|
|
|
/*
|
|
|
|
func watchNetworkInterfaces() {
|
|
|
|
// Get list of network interfaces
|
|
|
|
interfaces, _ := net.Interfaces()
|
|
|
|
|
|
|
|
// Set up a notification channel
|
|
|
|
notification := make(chan net.Interface)
|
|
|
|
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "watchNet()")
|
2023-02-18 23:37:11 -06:00
|
|
|
// Start goroutine to watch for changes
|
|
|
|
go func() {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "watchNet() func")
|
2023-02-18 23:37:11 -06:00
|
|
|
for {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "forever loop start")
|
2023-02-18 23:37:11 -06:00
|
|
|
// Check for changes in each interface
|
|
|
|
for _, i := range interfaces {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "something on i =", i)
|
2023-02-18 23:37:11 -06:00
|
|
|
if status := i.Flags & net.FlagUp; status != 0 {
|
|
|
|
notification <- i
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "something on i =", i)
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
}
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "forever loop end")
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
func IsIPv6(address string) bool {
|
|
|
|
return strings.Count(address, ":") >= 2
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *IPtype) IsReal() bool {
|
|
|
|
if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "\t\tIP is Real = false")
|
2023-02-18 23:37:11 -06:00
|
|
|
return false
|
|
|
|
} else {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "\t\tIP is Real = true")
|
2023-02-18 23:37:11 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsReal(ip *net.IP) bool {
|
|
|
|
if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "\t\tIP is Real = false")
|
2023-02-18 23:37:11 -06:00
|
|
|
return false
|
|
|
|
} else {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "\t\tIP is Real = true")
|
2023-02-18 23:37:11 -06:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func renameInterface(i *net.Interface) {
|
|
|
|
/*
|
|
|
|
/sbin/ip link set eth1 down
|
|
|
|
/sbin/ip link set eth1 name eth123
|
|
|
|
/sbin/ip link set eth123 up
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
// Will figure out if an interface was just added
|
|
|
|
func checkInterface(i net.Interface) {
|
|
|
|
val, ok := me.ifmap[i.Index]
|
|
|
|
if ! ok {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Info(i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
2023-02-18 23:37:11 -06:00
|
|
|
me.ifmap[i.Index] = new(IFtype)
|
|
|
|
me.ifmap[i.Index].gone = false
|
|
|
|
me.ifmap[i.Index].iface = &i
|
2023-03-26 16:17:32 -05:00
|
|
|
me.changed = true
|
2023-03-25 08:09:34 -05:00
|
|
|
if (me.Interfaces != nil) {
|
|
|
|
me.Interfaces.AddText(i.Name)
|
2023-03-25 08:40:48 -05:00
|
|
|
me.Interfaces.SetText(i.Name)
|
2023-03-25 08:09:34 -05:00
|
|
|
}
|
2023-02-18 23:37:11 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
me.ifmap[i.Index].gone = false
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Log(NET, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
|
2023-02-18 23:37:11 -06:00
|
|
|
if (val.iface.Name != i.Name) {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Info(val.iface.Name, "has changed to it's name to", i.Name)
|
2023-02-18 23:37:11 -06:00
|
|
|
me.ifmap[i.Index].iface = &i
|
2023-03-26 16:17:32 -05:00
|
|
|
me.changed = true
|
2023-03-25 08:09:34 -05:00
|
|
|
if (me.Interfaces != nil) {
|
|
|
|
me.Interfaces.AddText(i.Name)
|
2023-03-25 08:40:48 -05:00
|
|
|
me.Interfaces.SetText(i.Name)
|
2023-03-25 08:09:34 -05:00
|
|
|
}
|
2023-02-18 23:37:11 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-28 09:43:45 -06:00
|
|
|
/*
|
|
|
|
These are the real IP address you have been
|
|
|
|
given from DHCP
|
|
|
|
*/
|
|
|
|
func dhcpAAAA() []string {
|
2023-02-18 23:37:11 -06:00
|
|
|
var aaaa []string
|
|
|
|
|
|
|
|
for s, t := range me.ipmap {
|
|
|
|
if (t.IsReal()) {
|
|
|
|
if (t.ipv6) {
|
|
|
|
aaaa = append(aaaa, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aaaa
|
|
|
|
}
|
|
|
|
|
2023-12-20 03:13:43 -06:00
|
|
|
func realA() []string {
|
|
|
|
var a []string
|
|
|
|
|
|
|
|
for s, t := range me.ipmap {
|
|
|
|
if (t.IsReal()) {
|
|
|
|
if (t.ipv4) {
|
|
|
|
a = append(a, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2023-02-18 23:37:11 -06:00
|
|
|
func checkDNS() (map[string]*IPtype, map[string]*IPtype) {
|
|
|
|
var ipv4s map[string]*IPtype
|
|
|
|
var ipv6s map[string]*IPtype
|
|
|
|
|
|
|
|
ipv4s = make(map[string]*IPtype)
|
|
|
|
ipv6s = make(map[string]*IPtype)
|
|
|
|
|
|
|
|
for s, t := range me.ipmap {
|
|
|
|
i := t.iface
|
|
|
|
ipt := "IPv4"
|
|
|
|
if (t.ipv6) {
|
|
|
|
ipt = "IPv6"
|
|
|
|
}
|
|
|
|
if (t.IsReal()) {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Info("\tIP is Real ", ipt, i.Index, i.Name, s)
|
2023-02-18 23:37:11 -06:00
|
|
|
if (t.ipv6) {
|
|
|
|
ipv6s[s] = t
|
|
|
|
} else {
|
|
|
|
ipv4s[s] = t
|
|
|
|
}
|
|
|
|
} else {
|
2024-01-03 12:40:31 -06:00
|
|
|
log.Info("\tIP is not Real", ipt, i.Index, i.Name, s)
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ipv6s, ipv4s
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete network interfaces and ip addresses from the gui
|
2024-01-06 14:57:51 -06:00
|
|
|
func deleteChanges2() bool {
|
2023-12-20 03:13:43 -06:00
|
|
|
var changed bool = false
|
2023-02-18 23:37:11 -06:00
|
|
|
for i, t := range me.ifmap {
|
|
|
|
if (t.gone) {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Log(CHANGE, "DELETE int =", i, "name =", t.name, t.iface)
|
2023-02-18 23:37:11 -06:00
|
|
|
delete(me.ifmap, i)
|
2023-12-20 03:13:43 -06:00
|
|
|
changed = true
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
t.gone = true
|
|
|
|
}
|
|
|
|
for s, t := range me.ipmap {
|
|
|
|
if (t.gone) {
|
2024-01-03 19:33:13 -06:00
|
|
|
log.Log(CHANGE, "DELETE name =", s, "IPv4 =", t.ipv4)
|
|
|
|
log.Log(CHANGE, "DELETE name =", s, "IPv6 =", t.ipv6)
|
|
|
|
log.Log(CHANGE, "DELETE name =", s, "iface =", t.iface)
|
|
|
|
log.Log(CHANGE, "DELETE name =", s, "ip =", t.ip)
|
2023-02-18 23:37:11 -06:00
|
|
|
delete(me.ipmap, s)
|
2023-12-20 03:13:43 -06:00
|
|
|
changed = true
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|
|
|
|
t.gone = true
|
|
|
|
}
|
2023-12-20 03:13:43 -06:00
|
|
|
|
|
|
|
return changed
|
2023-02-18 23:37:11 -06:00
|
|
|
}
|