mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 10:46:57 -07:00
refactor if/else in network and packets packages
This commit is contained in:
parent
1e12891bfb
commit
ed6d40f163
6 changed files with 34 additions and 25 deletions
|
@ -147,9 +147,11 @@ func (t *Endpoint) String() string {
|
|||
|
||||
if t.HwAddress == "" {
|
||||
return t.IpAddress
|
||||
} else if t.Vendor == "" {
|
||||
}
|
||||
if t.Vendor == "" {
|
||||
return fmt.Sprintf("%s%s", ipPart, t.HwAddress)
|
||||
} else if t.Hostname == "" {
|
||||
}
|
||||
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))
|
||||
|
@ -159,10 +161,13 @@ func (t *Endpoint) OnMeta(meta map[string]string) {
|
|||
host := ""
|
||||
for k, v := range meta {
|
||||
// simple heuristics to get the longest candidate name
|
||||
if strings.HasSuffix(k, ":hostname") && len(v) > len(host) {
|
||||
host = v
|
||||
} else if k == "mdns:md" && len(v) > len(host) {
|
||||
host = v
|
||||
if len(v) > len(host) {
|
||||
if strings.HasSuffix(k, ":hostname"){
|
||||
host = v
|
||||
}
|
||||
if k == "mdns:md"{
|
||||
host = v
|
||||
}
|
||||
}
|
||||
t.Meta.Set(k, v)
|
||||
}
|
||||
|
|
|
@ -31,15 +31,14 @@ 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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,8 @@ func SetInterfaceChannel(iface string, channel int) error {
|
|||
out, err := core.Exec("iwconfig", []string{iface, "channel", fmt.Sprintf("%d", channel)})
|
||||
if err != nil {
|
||||
return err
|
||||
} else if out != "" {
|
||||
}
|
||||
if out != "" {
|
||||
return fmt.Errorf("Unexpected output while setting interface %s to channel %d: %s", iface, channel, out)
|
||||
}
|
||||
|
||||
|
@ -63,7 +64,8 @@ func processSupportedFrequencies(output string, err error) ([]int, error) {
|
|||
freqs := make([]int, 0)
|
||||
if err != nil {
|
||||
return freqs, err
|
||||
} else if output != "" {
|
||||
}
|
||||
if output != "" {
|
||||
scanner := bufio.NewScanner(strings.NewReader(output))
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
|
|
@ -10,9 +10,11 @@ import (
|
|||
func Dot11Freq2Chan(freq int) int {
|
||||
if freq <= 2472 {
|
||||
return ((freq - 2412) / 5) + 1
|
||||
} else if freq == 2484 {
|
||||
}
|
||||
if freq == 2484 {
|
||||
return 14
|
||||
} else if freq >= 5035 && freq <= 5865 {
|
||||
}
|
||||
if freq >= 5035 && freq <= 5865 {
|
||||
return ((freq - 5035) / 5) + 7
|
||||
}
|
||||
return 0
|
||||
|
@ -21,9 +23,11 @@ func Dot11Freq2Chan(freq int) int {
|
|||
func Dot11Chan2Freq(channel int) int {
|
||||
if channel <= 13 {
|
||||
return ((channel - 1) * 5) + 2412
|
||||
} else if channel == 14 {
|
||||
}
|
||||
if channel == 14 {
|
||||
return 2484
|
||||
} else if channel <= 173 {
|
||||
}
|
||||
if channel <= 173 {
|
||||
return ((channel - 7) * 5) + 5035
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue