ready to start looking for changes

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-02-17 11:10:44 -06:00
parent 6c5413a71f
commit 89aa949db3
5 changed files with 73 additions and 37 deletions

View File

@ -6,8 +6,9 @@ import (
)
type LogOptions struct {
LogFile string
LogFile string `help:"write all output to a file"`
Verbose bool
VerboseNet bool `arg:"--verbose-net" help:"debug network settings"`
// GuiDebug bool `help:"open up the wit/gui Debugging Window"`
// GuiDemo bool `help:"open the wit/gui Demo Window"`
User string `arg:"env:USER"`

45
log.go
View File

@ -5,17 +5,43 @@ package main
import (
"os"
golog "log"
"time"
"reflect"
"github.com/davecgh/go-spew/spew"
// "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(.1) # you know what this does? yes, it sleeps for 1/10th of a second
*/
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
and it all stops.
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
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.
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
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(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) {
if (LOGOFF) {
return

21
main.go
View File

@ -2,6 +2,7 @@
package main
import (
"runtime"
// "net"
// "github.com/fsnotify/fsnotify"
"git.wit.org/wit/gui"
@ -13,11 +14,27 @@ func main() {
// fmt.Println(args.Foo, args.Bar, args.User)
log("Toolkit = ", args.Toolkit)
me.ips = make(map[string]*IPtype)
me.ip = make(map[string]*IPtype)
// 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()
gui.Main(initGUI)
}

15
net.go
View File

@ -34,11 +34,6 @@ func watchNetworkInterfaces() {
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 {
@ -57,12 +52,13 @@ func IsReal(ip *net.IP) bool {
func scanInterfaces() {
ifaces, _ := net.Interfaces()
me.ifnew = ifaces
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(args.VerboseNet, SPEW, i)
log(DEBUGNET, SPEW, addrs)
for _, addr := range addrs {
log(DEBUGNET, "\taddr =", addr)
@ -75,15 +71,18 @@ func scanInterfaces() {
log(DEBUGNET, "\t\taddr.(type) =", v)
ip := v.IP
log(DEBUGNET, "\t\taddr.IP =", ip)
var t string
t = "IPv4"
if (IsIPv6(ip.String())) {
log(DEBUGNET, "\t\tIP is IPv6")
t = "IPv6"
} else {
log(DEBUGNET, "\t\tIP is IPv4")
}
if (IsReal(&ip)) {
log("\tIP is Real ", addr)
log("\tIP is Real ", t, i.Name, ip)
} 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 IsLoopback() =", ip.IsLoopback())

View File

@ -2,25 +2,27 @@
package main
import (
// "net"
// "github.com/fsnotify/fsnotify"
// "git.wit.org/wit/gui"
// arg "github.com/alexflint/go-arg"
"net"
)
// It's probably a terrible idea to call this 'me'
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 {
// IP string
IPv4 bool
IPv6 bool
LinkLocal bool
}
type Host struct {
Name string
domainname string
hostname string
fqdn string
ips map[string]*IPtype
nic *net.Interface
}