From 1215cdcf538d78d45930e49ab833fabbc358103c Mon Sep 17 00:00:00 2001 From: Yutaka Kato Date: Sat, 4 Jul 2020 06:14:03 +0900 Subject: [PATCH] #5 use ip command instead arp command if it available --- README.md | 4 ++-- resolver.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3c591b5..e623b06 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,13 @@ See [releases](https://github.com/mikan/arping-gui/releases) page. 1. Check available network adapter information (e.g. eth0) 2. Send ICMP ping to the target using native `ping` command -3. Lookup ARP table using native `arp` command +3. Lookup ARP table using native `arp` (`ip`) command ### MAC to IP 1. Check available network adapter information (e.g. eth0) 2. Send ICMP ping to the *broadcast* address using native `ping` command -3. Lookup ARP table using native `arp` command +3. Lookup ARP table using native `arp` (`ip`) command ## Limitations diff --git a/resolver.go b/resolver.go index 978d444..ccca014 100644 --- a/resolver.go +++ b/resolver.go @@ -21,7 +21,11 @@ func ip2mac(ip string, adapter adapter) (string, error) { arpCmd = exec.Command("arp", "-i", adapter.name, ip) default: pingCmd = exec.Command("ping", "-I", adapter.name, "-c", "1", ip) - arpCmd = exec.Command("arp", "-i", adapter.name, ip) + if _, err := exec.LookPath("ip"); err == nil { + arpCmd = exec.Command("ip", "neigh", "show", "dev", adapter.name, ip) + } else { + arpCmd = exec.Command("arp", "-i", adapter.name, ip) + } } if err := pingCmd.Run(); err != nil { return "", err @@ -51,7 +55,11 @@ func mac2ip(mac string, adapter adapter) (string, error) { default: mac = strings.ReplaceAll(strings.ToLower(mac), "-", ":") pingCmd = exec.Command("ping", "-I", adapter.name, "-c", "1", adapter.broadcast, "-b") - arpCmd = exec.Command("arp", "-a", "-i", adapter.name) + if _, err := exec.LookPath("ip"); err == nil { + arpCmd = exec.Command("ip", "neigh", "show", "dev", adapter.name) + } else { + arpCmd = exec.Command("arp", "-a", "-i", adapter.name) + } } if err := pingCmd.Run(); err != nil { fmt.Printf("WARNING: broadcast ping failed: %v\n", err)