ready to start looking for changes
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
6c5413a71f
commit
89aa949db3
3
args.go
3
args.go
|
@ -6,8 +6,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogOptions struct {
|
type LogOptions struct {
|
||||||
LogFile string
|
LogFile string `help:"write all output to a file"`
|
||||||
Verbose bool
|
Verbose bool
|
||||||
|
VerboseNet bool `arg:"--verbose-net" help:"debug network settings"`
|
||||||
// GuiDebug bool `help:"open up the wit/gui Debugging Window"`
|
// GuiDebug bool `help:"open up the wit/gui Debugging Window"`
|
||||||
// GuiDemo bool `help:"open the wit/gui Demo Window"`
|
// GuiDemo bool `help:"open the wit/gui Demo Window"`
|
||||||
User string `arg:"env:USER"`
|
User string `arg:"env:USER"`
|
||||||
|
|
45
log.go
45
log.go
|
@ -5,17 +5,43 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
golog "log"
|
golog "log"
|
||||||
|
"time"
|
||||||
"reflect"
|
"reflect"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
// "net"
|
// "net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var LOGOFF bool = false // turn this off, all logging stops
|
||||||
|
var WARN bool
|
||||||
|
var INFO bool
|
||||||
|
|
||||||
|
type spewt struct {
|
||||||
|
a bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var SPEW spewt
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
|
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
|
||||||
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
|
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
|
||||||
*/
|
*/
|
||||||
func sleep(a ...any) {
|
func sleep(a ...any) {
|
||||||
log("sleep", a)
|
if (a == nil) {
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log("sleep", a[0])
|
||||||
|
|
||||||
|
switch a[0].(type) {
|
||||||
|
case int:
|
||||||
|
time.Sleep(time.Duration(a[0].(int)) * time.Second)
|
||||||
|
case float64:
|
||||||
|
time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond)
|
||||||
|
default:
|
||||||
|
log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0]))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -37,24 +63,15 @@ func exit(a ...any) {
|
||||||
implementation is probably faster than all of those because you just set one bool to FALSE
|
implementation is probably faster than all of those because you just set one bool to FALSE
|
||||||
and it all stops.
|
and it all stops.
|
||||||
Sometimes I need to capture to stdout, sometimes stdout can't
|
Sometimes I need to capture to stdout, sometimes stdout can't
|
||||||
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread over 8 million references in every .go file. I'm tapping out and putting
|
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread
|
||||||
it in one place. here it is. Also, this makes having debug levels really fucking easy. You can define whatever level of logging you want from anywhere (command line)
|
over 8 million references in every .go file. I'm tapping out and putting
|
||||||
etc.
|
it in one place. here it is. Also, this makes having debug levels really fucking easy.
|
||||||
|
You can define whatever level of logging you want from anywhere (command line) etc.
|
||||||
|
|
||||||
log() # doesn't do anything
|
log() # doesn't do anything
|
||||||
log(stuff) # sends it to whatever log you define in a single place. here is the place
|
log(stuff) # sends it to whatever log you define in a single place. here is the place
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var LOGOFF bool // turn this off, all logging stops
|
|
||||||
var WARN bool
|
|
||||||
var INFO bool
|
|
||||||
|
|
||||||
type spewt struct {
|
|
||||||
a bool
|
|
||||||
}
|
|
||||||
|
|
||||||
var SPEW spewt
|
|
||||||
|
|
||||||
func log(a ...any) {
|
func log(a ...any) {
|
||||||
if (LOGOFF) {
|
if (LOGOFF) {
|
||||||
return
|
return
|
||||||
|
|
21
main.go
21
main.go
|
@ -2,6 +2,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
// "net"
|
// "net"
|
||||||
// "github.com/fsnotify/fsnotify"
|
// "github.com/fsnotify/fsnotify"
|
||||||
"git.wit.org/wit/gui"
|
"git.wit.org/wit/gui"
|
||||||
|
@ -13,11 +14,27 @@ func main() {
|
||||||
// fmt.Println(args.Foo, args.Bar, args.User)
|
// fmt.Println(args.Foo, args.Bar, args.User)
|
||||||
log("Toolkit = ", args.Toolkit)
|
log("Toolkit = ", args.Toolkit)
|
||||||
|
|
||||||
me.ips = make(map[string]*IPtype)
|
me.ip = make(map[string]*IPtype)
|
||||||
|
|
||||||
// gui.InitPlugins([]string{"andlabs"})
|
// gui.InitPlugins([]string{"andlabs"})
|
||||||
|
|
||||||
scanInterfaces()
|
|
||||||
|
if (runtime.GOOS == "linux") {
|
||||||
|
scanInterfaces()
|
||||||
|
} else {
|
||||||
|
log("Windows and MacOS don't work yet")
|
||||||
|
exit()
|
||||||
|
}
|
||||||
|
|
||||||
|
log()
|
||||||
|
log(true, "this is true")
|
||||||
|
log(false, "this is false")
|
||||||
|
sleep(.4)
|
||||||
|
sleep(.3)
|
||||||
|
sleep(.2)
|
||||||
|
sleep("done scanning net")
|
||||||
|
// exit("done scanning net")
|
||||||
|
|
||||||
watchNetworkInterfaces()
|
watchNetworkInterfaces()
|
||||||
gui.Main(initGUI)
|
gui.Main(initGUI)
|
||||||
}
|
}
|
||||||
|
|
15
net.go
15
net.go
|
@ -34,11 +34,6 @@ func watchNetworkInterfaces() {
|
||||||
log(DEBUGNET, "forever loop end")
|
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 {
|
func IsIPv6(address string) bool {
|
||||||
|
@ -57,12 +52,13 @@ func IsReal(ip *net.IP) bool {
|
||||||
|
|
||||||
func scanInterfaces() {
|
func scanInterfaces() {
|
||||||
ifaces, _ := net.Interfaces()
|
ifaces, _ := net.Interfaces()
|
||||||
|
me.ifnew = ifaces
|
||||||
log(DEBUGNET, SPEW, ifaces)
|
log(DEBUGNET, SPEW, ifaces)
|
||||||
for _, i := range ifaces {
|
for _, i := range ifaces {
|
||||||
addrs, _ := i.Addrs()
|
addrs, _ := i.Addrs()
|
||||||
// log("range ifaces = ", i)
|
// log("range ifaces = ", i)
|
||||||
log("*net.Interface.Name = ", i.Name)
|
log("*net.Interface.Name = ", i.Name)
|
||||||
log(SPEW, i)
|
log(args.VerboseNet, SPEW, i)
|
||||||
log(DEBUGNET, SPEW, addrs)
|
log(DEBUGNET, SPEW, addrs)
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
log(DEBUGNET, "\taddr =", addr)
|
log(DEBUGNET, "\taddr =", addr)
|
||||||
|
@ -75,15 +71,18 @@ func scanInterfaces() {
|
||||||
log(DEBUGNET, "\t\taddr.(type) =", v)
|
log(DEBUGNET, "\t\taddr.(type) =", v)
|
||||||
ip := v.IP
|
ip := v.IP
|
||||||
log(DEBUGNET, "\t\taddr.IP =", ip)
|
log(DEBUGNET, "\t\taddr.IP =", ip)
|
||||||
|
var t string
|
||||||
|
t = "IPv4"
|
||||||
if (IsIPv6(ip.String())) {
|
if (IsIPv6(ip.String())) {
|
||||||
log(DEBUGNET, "\t\tIP is IPv6")
|
log(DEBUGNET, "\t\tIP is IPv6")
|
||||||
|
t = "IPv6"
|
||||||
} else {
|
} else {
|
||||||
log(DEBUGNET, "\t\tIP is IPv4")
|
log(DEBUGNET, "\t\tIP is IPv4")
|
||||||
}
|
}
|
||||||
if (IsReal(&ip)) {
|
if (IsReal(&ip)) {
|
||||||
log("\tIP is Real ", addr)
|
log("\tIP is Real ", t, i.Name, ip)
|
||||||
} else {
|
} else {
|
||||||
log("\tIP is not Real", addr)
|
log("\tIP is not Real", t, i.Name, ip)
|
||||||
}
|
}
|
||||||
log(DEBUGNET, "\t\tIP is IsPrivate() =", ip.IsPrivate())
|
log(DEBUGNET, "\t\tIP is IsPrivate() =", ip.IsPrivate())
|
||||||
log(DEBUGNET, "\t\tIP is IsLoopback() =", ip.IsLoopback())
|
log(DEBUGNET, "\t\tIP is IsLoopback() =", ip.IsLoopback())
|
||||||
|
|
26
structs.go
26
structs.go
|
@ -2,25 +2,27 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "net"
|
"net"
|
||||||
// "github.com/fsnotify/fsnotify"
|
|
||||||
// "git.wit.org/wit/gui"
|
|
||||||
// arg "github.com/alexflint/go-arg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// It's probably a terrible idea to call this 'me'
|
||||||
var me Host
|
var me Host
|
||||||
|
|
||||||
|
type Host struct {
|
||||||
|
domainname string // kernel.org
|
||||||
|
hostname string // mirrors
|
||||||
|
fqdn string // mirrors.kernel.org
|
||||||
|
ip map[string]*IPtype
|
||||||
|
ifmap map[int]*net.Interface
|
||||||
|
ifcur []net.Interface // the current network settings
|
||||||
|
ifnew []net.Interface // used to look for changes
|
||||||
|
ipchange bool // set to true if things change
|
||||||
|
}
|
||||||
|
|
||||||
type IPtype struct {
|
type IPtype struct {
|
||||||
// IP string
|
// IP string
|
||||||
IPv4 bool
|
IPv4 bool
|
||||||
IPv6 bool
|
IPv6 bool
|
||||||
LinkLocal bool
|
LinkLocal bool
|
||||||
}
|
nic *net.Interface
|
||||||
|
|
||||||
type Host struct {
|
|
||||||
Name string
|
|
||||||
domainname string
|
|
||||||
hostname string
|
|
||||||
fqdn string
|
|
||||||
ips map[string]*IPtype
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue