Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5 Use ip command instead arp command if it available #6

Merged
merged 1 commit into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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