starting a checkDNS() function
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
bccb9e98ed
commit
1dfd895074
9
Makefile
9
Makefile
|
@ -1,18 +1,21 @@
|
||||||
run: build
|
run: build
|
||||||
reset
|
|
||||||
./control-panel-dns
|
./control-panel-dns
|
||||||
|
|
||||||
verbose: build
|
verbose: build
|
||||||
reset
|
|
||||||
./control-panel-dns --verbose --verbose-net --gui-debug --toolkit-debug
|
./control-panel-dns --verbose --verbose-net --gui-debug --toolkit-debug
|
||||||
|
|
||||||
build-release:
|
build-release:
|
||||||
|
reset
|
||||||
go get -v -u -x .
|
go get -v -u -x .
|
||||||
go build
|
go build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
reset
|
||||||
GO111MODULE="off" go get -v -x .
|
GO111MODULE="off" go get -v -x .
|
||||||
GO111MODULE="off" go build
|
GO111MODULE="off" go build -v
|
||||||
|
|
||||||
|
test:
|
||||||
|
GO111MODULE="off" go test -v
|
||||||
|
|
||||||
update:
|
update:
|
||||||
GO111MODULE="off" go get -v -u -x .
|
GO111MODULE="off" go get -v -u -x .
|
||||||
|
|
16
gui.go
16
gui.go
|
@ -66,6 +66,22 @@ func addDNSTab(window *gui.Node, title string) {
|
||||||
g2.NewButton("scanInterfaces()", func () {
|
g2.NewButton("scanInterfaces()", func () {
|
||||||
scanInterfaces()
|
scanInterfaces()
|
||||||
})
|
})
|
||||||
|
g2.NewButton("dump Host.ifmap", func () {
|
||||||
|
for i, t := range me.ifmap {
|
||||||
|
log("int =", i, "name =", t.name, t.iface)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
g2.NewButton("dump Host.ipmap", func () {
|
||||||
|
for s, t := range me.ipmap {
|
||||||
|
log("name =", s, "ipv4 =", t.ipv4)
|
||||||
|
log("name =", s, "ipv6 =", t.ipv6)
|
||||||
|
log("name =", s, "iface =", t.iface)
|
||||||
|
log("name =", s, "ip =", t.ip)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
g2.NewButton("checkDNS()", func () {
|
||||||
|
checkDNS()
|
||||||
|
})
|
||||||
g2.NewButton("os.Hostname()", func () {
|
g2.NewButton("os.Hostname()", func () {
|
||||||
name, err = os.Hostname()
|
name, err = os.Hostname()
|
||||||
log("name =", name, err)
|
log("name =", name, err)
|
||||||
|
|
9
main.go
9
main.go
|
@ -3,7 +3,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"net"
|
// "net"
|
||||||
"git.wit.org/wit/gui"
|
"git.wit.org/wit/gui"
|
||||||
arg "github.com/alexflint/go-arg"
|
arg "github.com/alexflint/go-arg"
|
||||||
)
|
)
|
||||||
|
@ -12,8 +12,8 @@ func main() {
|
||||||
arg.MustParse(&args)
|
arg.MustParse(&args)
|
||||||
|
|
||||||
// initialize the maps to track IP addresses and network interfaces
|
// initialize the maps to track IP addresses and network interfaces
|
||||||
me.ip = make(map[string]*IPtype)
|
me.ipmap = make(map[string]*IPtype)
|
||||||
me.ifmap = make(map[int]*net.Interface)
|
me.ifmap = make(map[int]*IFtype)
|
||||||
|
|
||||||
go checkNetworkChanges()
|
go checkNetworkChanges()
|
||||||
|
|
||||||
|
@ -26,6 +26,9 @@ func main() {
|
||||||
sleep("done scanning net")
|
sleep("done scanning net")
|
||||||
// exit("done scanning net")
|
// exit("done scanning net")
|
||||||
|
|
||||||
|
// Example_listLink()
|
||||||
|
// exit()
|
||||||
|
|
||||||
log("Toolkit = ", args.Toolkit)
|
log("Toolkit = ", args.Toolkit)
|
||||||
// gui.InitPlugins([]string{"andlabs"})
|
// gui.InitPlugins([]string{"andlabs"})
|
||||||
gui.Main(initGUI)
|
gui.Main(initGUI)
|
||||||
|
|
100
net.go
100
net.go
|
@ -42,6 +42,16 @@ func IsIPv6(address string) bool {
|
||||||
return strings.Count(address, ":") >= 2
|
return strings.Count(address, ":") >= 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *IPtype) IsReal() bool {
|
||||||
|
if (t.ip.IsPrivate() || t.ip.IsLoopback() || t.ip.IsLinkLocalUnicast()) {
|
||||||
|
log(DEBUGNET, "\t\tIP is Real = false")
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
log(DEBUGNET, "\t\tIP is Real = true")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func IsReal(ip *net.IP) bool {
|
func IsReal(ip *net.IP) bool {
|
||||||
if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) {
|
if (ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()) {
|
||||||
log(DEBUGNET, "\t\tIP is Real = false")
|
log(DEBUGNET, "\t\tIP is Real = false")
|
||||||
|
@ -52,45 +62,78 @@ func IsReal(ip *net.IP) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkInterface(i *net.Interface) {
|
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]
|
val, ok := me.ifmap[i.Index]
|
||||||
if ! ok {
|
if ! ok {
|
||||||
log(i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
log(i.Name, "is a new network interface. The linux kernel index =", i.Index)
|
||||||
me.ifmap[i.Index] = i
|
me.ifmap[i.Index] = new(IFtype)
|
||||||
|
me.ifmap[i.Index].gone = false
|
||||||
|
me.ifmap[i.Index].iface = &i
|
||||||
me.ipchange = true
|
me.ipchange = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log(args.VerboseNet, "me.ifmap[i] does exist. Need to compare everything.", me.ifmap[i.Index].Name)
|
me.ifmap[i.Index].gone = false
|
||||||
if (me.ifmap[i.Index].Name != val.Name) {
|
log(args.VerboseNet, "me.ifmap[i] does exist. Need to compare everything.", i.Index, i.Name, val.iface.Index, val.iface.Name)
|
||||||
log(val.Name, "has changed to it's name to", i.Name)
|
if (val.iface.Name != i.Name) {
|
||||||
me.ifmap[i.Index] = i
|
log(val.iface.Name, "has changed to it's name to", i.Name)
|
||||||
|
me.ifmap[i.Index].iface = &i
|
||||||
me.ipchange = true
|
me.ipchange = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func isNewIPNet(ip *net.IPNet, i *net.Interface) bool {
|
func checkDNS() {
|
||||||
|
for s, t := range me.ipmap {
|
||||||
|
i := t.iface
|
||||||
|
ipt := "IPv4"
|
||||||
|
if (t.ipv6) {
|
||||||
|
ipt = "IPv6"
|
||||||
|
}
|
||||||
|
if (t.IsReal()) {
|
||||||
|
log("\tIP is Real ", ipt, i.Index, i.Name, s)
|
||||||
|
} else {
|
||||||
|
log("\tIP is not Real", ipt, i.Index, i.Name, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Will figure out if an IP address is new
|
||||||
|
func checkIP(ip *net.IPNet, i net.Interface) bool {
|
||||||
log(args.VerboseNet, "\t\taddr.(type) = *net.IPNet")
|
log(args.VerboseNet, "\t\taddr.(type) = *net.IPNet")
|
||||||
log(args.VerboseNet, "\t\taddr.(type) =", ip)
|
log(args.VerboseNet, "\t\taddr.(type) =", ip)
|
||||||
var realip string
|
var realip string
|
||||||
realip = ip.IP.String()
|
realip = ip.IP.String()
|
||||||
|
|
||||||
val, ok := me.ip[realip]
|
val, ok := me.ipmap[realip]
|
||||||
if ok {
|
if ok {
|
||||||
log(args.VerboseNet, val.IPNet.IP, "is already a defined IP address")
|
log(args.VerboseNet, val.ipnet.IP.String(), "is already a defined IP address")
|
||||||
|
me.ipmap[realip].gone = false
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
me.ip[realip] = new(IPtype)
|
me.ipmap[realip] = new(IPtype)
|
||||||
me.ip[realip].IPNet = ip
|
me.ipmap[realip].gone = false
|
||||||
|
me.ipmap[realip].ipv4 = true
|
||||||
|
me.ipmap[realip].ipnet = ip
|
||||||
|
me.ipmap[realip].ip = ip.IP
|
||||||
|
me.ipmap[realip].iface = &i
|
||||||
t := "IPv4"
|
t := "IPv4"
|
||||||
if (IsIPv6(ip.String())) {
|
if (IsIPv6(ip.String())) {
|
||||||
me.ip[realip].IPv6 = true
|
me.ipmap[realip].ipv6 = true
|
||||||
me.ip[realip].IPv4 = false
|
me.ipmap[realip].ipv4 = false
|
||||||
t = "IPv6"
|
t = "IPv6"
|
||||||
} else {
|
} else {
|
||||||
me.ip[realip].IPv6 = false
|
me.ipmap[realip].ipv6 = false
|
||||||
me.ip[realip].IPv4 = true
|
me.ipmap[realip].ipv4 = true
|
||||||
}
|
}
|
||||||
if (IsReal(&ip.IP)) {
|
if (IsReal(&ip.IP)) {
|
||||||
log("\tIP is Real ", t, i.Index, i.Name, realip)
|
log("\tIP is Real ", t, i.Index, i.Name, realip)
|
||||||
|
@ -100,6 +143,7 @@ func isNewIPNet(ip *net.IPNet, i *net.Interface) bool {
|
||||||
log(args.VerboseNet, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
|
log(args.VerboseNet, "\t\tIP is IsPrivate() =", ip.IP.IsPrivate())
|
||||||
log(args.VerboseNet, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
|
log(args.VerboseNet, "\t\tIP is IsLoopback() =", ip.IP.IsLoopback())
|
||||||
log(args.VerboseNet, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
|
log(args.VerboseNet, "\t\tIP is IsLinkLocalUnicast() =", ip.IP.IsLinkLocalUnicast())
|
||||||
|
// log("HERE HERE", "realip =", realip, "me.ip[realip]=", me.ipmap[realip])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +155,7 @@ func scanInterfaces() {
|
||||||
for _, i := range ifaces {
|
for _, i := range ifaces {
|
||||||
addrs, _ := i.Addrs()
|
addrs, _ := i.Addrs()
|
||||||
// log("range ifaces = ", i)
|
// log("range ifaces = ", i)
|
||||||
checkInterface(&i)
|
checkInterface(i)
|
||||||
log(args.VerboseNet, "*net.Interface.Name = ", i.Name, i.Index)
|
log(args.VerboseNet, "*net.Interface.Name = ", i.Name, i.Index)
|
||||||
log(args.VerboseNet, SPEW, i)
|
log(args.VerboseNet, SPEW, i)
|
||||||
log(DEBUGNET, SPEW, addrs)
|
log(DEBUGNET, SPEW, addrs)
|
||||||
|
@ -122,11 +166,33 @@ func scanInterfaces() {
|
||||||
log(DEBUGNET, "\tLookupIP(addr) =", ips)
|
log(DEBUGNET, "\tLookupIP(addr) =", ips)
|
||||||
switch v := addr.(type) {
|
switch v := addr.(type) {
|
||||||
case *net.IPNet:
|
case *net.IPNet:
|
||||||
isNewIPNet(v, &i)
|
checkIP(v, i)
|
||||||
// log("\t\tIP is () =", ip.())
|
// log("\t\tIP is () =", ip.())
|
||||||
default:
|
default:
|
||||||
log(DEBUGNET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v)
|
log(DEBUGNET, "\t\taddr.(type) = NO IDEA WHAT TO DO HERE v =", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
deleteChanges()
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete network interfaces and ip addresses from the gui
|
||||||
|
func deleteChanges() {
|
||||||
|
for i, t := range me.ifmap {
|
||||||
|
if (t.gone) {
|
||||||
|
log("DELETE int =", i, "name =", t.name, t.iface)
|
||||||
|
delete(me.ifmap, i)
|
||||||
|
}
|
||||||
|
t.gone = true
|
||||||
|
}
|
||||||
|
for s, t := range me.ipmap {
|
||||||
|
if (t.gone) {
|
||||||
|
log("DELETE name =", s, "IPv4 =", t.ipv4)
|
||||||
|
log("DELETE name =", s, "IPv6 =", t.ipv6)
|
||||||
|
log("DELETE name =", s, "iface =", t.iface)
|
||||||
|
log("DELETE name =", s, "ip =", t.ip)
|
||||||
|
delete(me.ipmap, s)
|
||||||
|
}
|
||||||
|
t.gone = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jsimonetti/rtnetlink"
|
||||||
|
)
|
||||||
|
|
||||||
|
// List all interfaces
|
||||||
|
func Example_listLink() {
|
||||||
|
// Dial a connection to the rtnetlink socket
|
||||||
|
conn, err := rtnetlink.Dial(nil)
|
||||||
|
if err != nil {
|
||||||
|
exit(err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
// Request a list of interfaces
|
||||||
|
msg, err := conn.Link.List()
|
||||||
|
if err != nil {
|
||||||
|
log(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log("%#v", msg)
|
||||||
|
log(SPEW, msg)
|
||||||
|
}
|
23
structs.go
23
structs.go
|
@ -12,17 +12,24 @@ type Host struct {
|
||||||
hostname string // mirrors
|
hostname string // mirrors
|
||||||
domainname string // kernel.org
|
domainname string // kernel.org
|
||||||
fqdn string // mirrors.kernel.org
|
fqdn string // mirrors.kernel.org
|
||||||
ip map[string]*IPtype
|
ipmap map[string]*IPtype // the current ip addresses
|
||||||
ifmap map[int]*net.Interface // the current network settings
|
ifmap map[int]*IFtype // the current interfaces
|
||||||
// ifnew []net.Interface // used to look for changes
|
|
||||||
ipchange bool // set to true if things change
|
ipchange bool // set to true if things change
|
||||||
}
|
}
|
||||||
|
|
||||||
type IPtype struct {
|
type IPtype struct {
|
||||||
// IP string
|
gone bool // used to track if the ip exists
|
||||||
IPv4 bool
|
ipv6 bool // the future
|
||||||
IPv6 bool
|
ipv4 bool // the past
|
||||||
LinkLocal bool
|
LinkLocal bool
|
||||||
Interface *net.Interface
|
iface *net.Interface
|
||||||
IPNet *net.IPNet
|
ip net.IP
|
||||||
|
ipnet *net.IPNet
|
||||||
|
}
|
||||||
|
|
||||||
|
type IFtype struct {
|
||||||
|
gone bool // used to track if the interface exists
|
||||||
|
name string // just a shortcut to the name. maybe this is dumb
|
||||||
|
// up bool // could be used to track ifup/ifdown
|
||||||
|
iface *net.Interface
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue