mirror of
https://github.com/bettercap/bettercap
synced 2025-07-06 21:12:05 -07:00
Replace arp from net-tools by ip from iproute2 (linux)
This commit is contained in:
parent
3cc5faa297
commit
c55284429e
3 changed files with 12 additions and 6 deletions
|
@ -4,3 +4,6 @@ import "regexp"
|
||||||
|
|
||||||
var ArpTableParser = regexp.MustCompile("^[^\\d\\.]+([\\d\\.]+).+\\s+([a-f0-9:]{11,17})\\s+on\\s+([^\\s]+)\\s+.+$")
|
var ArpTableParser = regexp.MustCompile("^[^\\d\\.]+([\\d\\.]+).+\\s+([a-f0-9:]{11,17})\\s+on\\s+([^\\s]+)\\s+.+$")
|
||||||
var ArpTableTokens = 4
|
var ArpTableTokens = 4
|
||||||
|
var ArpTableTokenIndex = []uint{1, 2, 3}
|
||||||
|
var ArpCmd = "arp"
|
||||||
|
var ArpCmdOpts = []string{"-a", "-n"}
|
||||||
|
|
|
@ -2,5 +2,8 @@ package net
|
||||||
|
|
||||||
import "regexp"
|
import "regexp"
|
||||||
|
|
||||||
var ArpTableParser = regexp.MustCompile("^[^\\d\\.]+([\\d\\.]+).+\\s+([a-f0-9:]{17}).+\\s+(.+)$")
|
var ArpTableParser = regexp.MustCompile("^([\\d\\.]+)\\s+dev\\s+(\\w+)\\s+\\w+\\s+([a-f0-9:]{17})\\s+\\w+$")
|
||||||
var ArpTableTokens = 4
|
var ArpTableTokens = 4
|
||||||
|
var ArpTableTokenIndex = []uint{1, 3, 2}
|
||||||
|
var ArpCmd = "ip"
|
||||||
|
var ArpCmdOpts = []string{"neigh"}
|
||||||
|
|
|
@ -12,8 +12,8 @@ func ArpUpdate(iface string) (ArpTable, error) {
|
||||||
// Signal we parsed the ARP table at least once.
|
// Signal we parsed the ARP table at least once.
|
||||||
arp_parsed = true
|
arp_parsed = true
|
||||||
|
|
||||||
// Run "arp -an" and parse the output.
|
// Run "arp -an" (darwin) or "ip neigh" (linux) and parse the output
|
||||||
output, err := core.Exec("arp", []string{"-a", "-n"})
|
output, err := core.Exec(ArpCmd, ArpCmdOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return arp_table, err
|
return arp_table, err
|
||||||
}
|
}
|
||||||
|
@ -22,9 +22,9 @@ func ArpUpdate(iface string) (ArpTable, error) {
|
||||||
for _, line := range strings.Split(output, "\n") {
|
for _, line := range strings.Split(output, "\n") {
|
||||||
m := ArpTableParser.FindStringSubmatch(line)
|
m := ArpTableParser.FindStringSubmatch(line)
|
||||||
if len(m) == ArpTableTokens {
|
if len(m) == ArpTableTokens {
|
||||||
address := m[1]
|
address := m[ArpTableTokenIndex[0]]
|
||||||
mac := m[2]
|
mac := m[ArpTableTokenIndex[1]]
|
||||||
ifname := m[3]
|
ifname := m[ArpTableTokenIndex[2]]
|
||||||
|
|
||||||
if ifname == iface {
|
if ifname == iface {
|
||||||
new_table[address] = mac
|
new_table[address] = mac
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue