arp-scanでLANにつながっているデバイスのIPアドレスを調べる

先日、RaspberryPiを触っていた時に、LANに接続している内のIPアドレスを知る方法はないかと思っていろいろ調べてみた。すると、arp-scanというコマンドがあった。

$ arp -i en0 -a
? (192.168.11.1) at 0:24:a5:f:8f:ae on en0 ifscope [ethernet]
? (192.168.11.14) at 70:48:f:74:ce:b on en0 ifscope [ethernet]
? (192.168.11.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]
? (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet]
broadcasthost (255.255.255.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]

arpコマンドでもある程度は出るんだけど、arp-scanコマンドを使うとよりわかりやすい情報を見ることができる。

Macではbrew install arp-scanで簡単にインストールできる。

インストールしたらコマンドを実行すると、次のような結果が出力される。

$ sudo arp-scan -l
Password:
Interface: en0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.11.1    00:24:a5:0f:8f:ae   Buffalo Inc.
192.168.11.7    00:17:88:1c:ac:62   Philips Lighting BV
192.168.11.15   b8:27:eb:07:66:12   Raspberry Pi Foundation
192.168.11.8    00:25:00:4d:f8:90   Apple, Inc
192.168.11.10   84:d6:d0:a1:c3:f9   (Unknown)
192.168.11.9    f0:f6:1c:d0:0c:65   (Unknown)

これを見ると、RaspberryPiのIPアドレス192.168.11.15であることがわかる。便利。