This commit is contained in:
Edznux 2018-10-28 17:42:25 +01:00
commit 2fe8999b2d
54 changed files with 473 additions and 542 deletions

View file

@ -147,11 +147,9 @@ func (t *Endpoint) String() string {
if t.HwAddress == "" {
return t.IpAddress
}
if t.Vendor == "" {
} else if t.Vendor == "" {
return fmt.Sprintf("%s%s", ipPart, t.HwAddress)
}
if t.Hostname == "" {
} else if t.Hostname == "" {
return fmt.Sprintf("%s%s ( %s )", ipPart, t.HwAddress, t.Vendor)
}
return fmt.Sprintf("%s%s ( %s ) - %s", ipPart, t.HwAddress, t.Vendor, tui.Bold(t.Hostname))
@ -161,13 +159,10 @@ func (t *Endpoint) OnMeta(meta map[string]string) {
host := ""
for k, v := range meta {
// simple heuristics to get the longest candidate name
if len(v) > len(host) {
if strings.HasSuffix(k, ":hostname") {
host = v
}
if k == "mdns:md" {
host = v
}
if strings.HasSuffix(k, ":hostname") && len(v) > len(host) {
host = v
} else if k == "mdns:md" && len(v) > len(host) {
host = v
}
t.Meta.Set(k, v)
}

View file

@ -31,14 +31,15 @@ func FindGateway(iface *Endpoint) (*Endpoint, error) {
if gateway == iface.IpAddress {
Debug("gateway is the interface")
return iface, nil
} else {
// we have the address, now we need its mac
mac, err := ArpLookup(ifName, gateway, false)
if err != nil {
return nil, err
}
Debug("gateway is %s[%s]", gateway, mac)
return NewEndpoint(gateway, mac), nil
}
// we have the address, now we need its mac
mac, err := ArpLookup(ifName, gateway, false)
if err != nil {
return nil, err
}
Debug("gateway is %s[%s]", gateway, mac)
return NewEndpoint(gateway, mac), nil
})
}
}

View file

@ -50,8 +50,7 @@ func SetInterfaceChannel(iface string, channel int) error {
out, err := core.Exec("iwconfig", []string{iface, "channel", fmt.Sprintf("%d", channel)})
if err != nil {
return err
}
if out != "" {
} else if out != "" {
return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out)
}
@ -64,8 +63,7 @@ func processSupportedFrequencies(output string, err error) ([]int, error) {
freqs := make([]int, 0)
if err != nil {
return freqs, err
}
if output != "" {
} else if output != "" {
scanner := bufio.NewScanner(strings.NewReader(output))
for scanner.Scan() {
line := scanner.Text()

View file

@ -10,11 +10,9 @@ import (
func Dot11Freq2Chan(freq int) int {
if freq <= 2472 {
return ((freq - 2412) / 5) + 1
}
if freq == 2484 {
} else if freq == 2484 {
return 14
}
if freq >= 5035 && freq <= 5865 {
} else if freq >= 5035 && freq <= 5865 {
return ((freq - 5035) / 5) + 7
}
return 0
@ -23,11 +21,9 @@ func Dot11Freq2Chan(freq int) int {
func Dot11Chan2Freq(channel int) int {
if channel <= 13 {
return ((channel - 1) * 5) + 2412
}
if channel == 14 {
} else if channel == 14 {
return 2484
}
if channel <= 173 {
} else if channel <= 173 {
return ((channel - 7) * 5) + 5035
}

View file

@ -19,10 +19,11 @@ func cleanESSID(essid string) string {
res := ""
for _, c := range essid {
if !strconv.IsPrint(c) {
if strconv.IsPrint(c) {
res += string(c)
} else {
break
}
res += string(c)
}
return res
}