Skip to content

Commit

Permalink
Merge pull request #6 from mikan/5-use-ip-cmd
Browse files Browse the repository at this point in the history
#5 Use ip command instead arp command if it available
  • Loading branch information
mikan authored Jul 3, 2020
2 parents 277c717 + 1215cdc commit a57700b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a57700b

Please sign in to comment.