hostname check basically working
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
27696b9764
commit
e9f1723dbc
12
hostname.go
12
hostname.go
|
@ -42,9 +42,19 @@ func getHostname() {
|
||||||
// On Linux, /etc/hosts, /etc/hostname
|
// On Linux, /etc/hosts, /etc/hostname
|
||||||
// and domainname and hostname
|
// and domainname and hostname
|
||||||
func goodHostname(h string) bool {
|
func goodHostname(h string) bool {
|
||||||
hostname := shell.Cat("/etc/hostname")
|
hostname := shell.Chomp(shell.Cat("/etc/hostname"))
|
||||||
log.Println("hostname =", hostname)
|
log.Println("hostname =", hostname)
|
||||||
|
|
||||||
|
hs := run("hostname -s")
|
||||||
|
dn := run("domainname")
|
||||||
|
log.Println("hostname short =", hs, "domainname =", dn)
|
||||||
|
|
||||||
|
tmp := hs + "." + dn
|
||||||
|
if (hostname == tmp) {
|
||||||
|
log.Println("hostname seems to be good", hostname)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
main.go
9
main.go
|
@ -25,16 +25,16 @@ func main() {
|
||||||
me.ipmap = make(map[string]*IPtype)
|
me.ipmap = make(map[string]*IPtype)
|
||||||
me.dnsmap = make(map[string]*IPtype)
|
me.dnsmap = make(map[string]*IPtype)
|
||||||
me.ifmap = make(map[int]*IFtype)
|
me.ifmap = make(map[int]*IFtype)
|
||||||
me.dnsTTL = 5 // recheck DNS is working every 2 minutes // TODO: watch rx packets?
|
me.dnsTTL = 2 // recheck DNS is working every 2 minutes // TODO: watch rx packets?
|
||||||
|
|
||||||
// will set all debugging flags
|
// will set all debugging flags
|
||||||
// gui.SetDebug(true)
|
// gui.SetDebug(true)
|
||||||
|
|
||||||
// myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui")
|
// myGui = gui.New().InitEmbed(resToolkit).LoadToolkit("gocui")
|
||||||
myGui = gui.New().Default()
|
myGui = gui.New().Default()
|
||||||
sleep(1)
|
sleep(.2)
|
||||||
setupControlPanelWindow()
|
setupControlPanelWindow()
|
||||||
sleep(1)
|
sleep(.2)
|
||||||
if (args.GuiDebug) {
|
if (args.GuiDebug) {
|
||||||
gui.DebugWindow()
|
gui.DebugWindow()
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,8 @@ func main() {
|
||||||
*/
|
*/
|
||||||
func checkNetworkChanges() {
|
func checkNetworkChanges() {
|
||||||
var ttl int = 0
|
var ttl int = 0
|
||||||
var ttlsleep int = 5
|
|
||||||
for {
|
for {
|
||||||
sleep(ttlsleep)
|
sleep(0.5)
|
||||||
ttl -= 1
|
ttl -= 1
|
||||||
if (ttl < 0) {
|
if (ttl < 0) {
|
||||||
if (runtime.GOOS == "linux") {
|
if (runtime.GOOS == "linux") {
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"git.wit.org/wit/shell"
|
||||||
|
)
|
||||||
|
|
||||||
|
func run(s string) string {
|
||||||
|
cmdArgs := strings.Fields(s)
|
||||||
|
// Define the command you want to run
|
||||||
|
// cmd := exec.Command(cmdArgs)
|
||||||
|
cmd := exec.Command(cmdArgs[0], cmdArgs[1:len(cmdArgs)]...)
|
||||||
|
|
||||||
|
// Create a buffer to capture the output
|
||||||
|
var out bytes.Buffer
|
||||||
|
|
||||||
|
// Set the output of the command to the buffer
|
||||||
|
cmd.Stdout = &out
|
||||||
|
|
||||||
|
// Run the command
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error running command:", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp := shell.Chomp(out.String())
|
||||||
|
// Output the results
|
||||||
|
fmt.Println("Command Output:", tmp)
|
||||||
|
|
||||||
|
return tmp
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue