mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 18:57:17 -07:00
balls
This commit is contained in:
parent
6e6eb688d7
commit
1cffa33264
7 changed files with 74 additions and 75 deletions
14
net/arp.go
14
net/arp.go
|
@ -8,9 +8,9 @@ import (
|
|||
type ArpTable map[string]string
|
||||
|
||||
var (
|
||||
arp_parsed = false
|
||||
arp_lock = &sync.Mutex{}
|
||||
arp_table = make(ArpTable)
|
||||
arpWasParsed = false
|
||||
arpLock = &sync.Mutex{}
|
||||
arpTable = make(ArpTable)
|
||||
)
|
||||
|
||||
func ArpDiff(current, before ArpTable) ArpTable {
|
||||
|
@ -34,7 +34,7 @@ func ArpLookup(iface string, address string, refresh bool) (string, error) {
|
|||
}
|
||||
|
||||
// Lookup the hardware address of this ip.
|
||||
if mac, found := arp_table[address]; found == true {
|
||||
if mac, found := arpTable[address]; found == true {
|
||||
return mac, nil
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ func ArpLookup(iface string, address string, refresh bool) (string, error) {
|
|||
}
|
||||
|
||||
func ArpParsed() bool {
|
||||
arp_lock.Lock()
|
||||
defer arp_lock.Unlock()
|
||||
return arp_parsed
|
||||
arpLock.Lock()
|
||||
defer arpLock.Unlock()
|
||||
return arpWasParsed
|
||||
}
|
||||
|
|
|
@ -6,19 +6,19 @@ import (
|
|||
)
|
||||
|
||||
func ArpUpdate(iface string) (ArpTable, error) {
|
||||
arp_lock.Lock()
|
||||
defer arp_lock.Unlock()
|
||||
arpLock.Lock()
|
||||
defer arpLock.Unlock()
|
||||
|
||||
// Signal we parsed the ARP table at least once.
|
||||
arp_parsed = true
|
||||
arpWasParsed = true
|
||||
|
||||
// Run "arp -an" (darwin) or "ip neigh" (linux) and parse the output
|
||||
output, err := core.Exec(ArpCmd, ArpCmdOpts)
|
||||
if err != nil {
|
||||
return arp_table, err
|
||||
return arpTable, err
|
||||
}
|
||||
|
||||
new_table := make(ArpTable)
|
||||
newTable := make(ArpTable)
|
||||
for _, line := range strings.Split(output, "\n") {
|
||||
m := ArpTableParser.FindStringSubmatch(line)
|
||||
if len(m) == ArpTableTokens {
|
||||
|
@ -27,12 +27,12 @@ func ArpUpdate(iface string) (ArpTable, error) {
|
|||
ifname := m[ArpTableTokenIndex[2]]
|
||||
|
||||
if ifname == iface {
|
||||
new_table[address] = mac
|
||||
newTable[address] = mac
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arp_table = new_table
|
||||
arpTable = newTable
|
||||
|
||||
return arp_table, nil
|
||||
return arpTable, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue