如何动态查看 dnsmasq 客户端 MAC 地址?

如何动态查看 dnsmasq 客户端 MAC 地址?

如果我已经知道客户端 IP,我知道它/var/log/dnsmasq.log包含如下日志

6 月 13 日 12:22:42 dnsmasq-dhcp[499]: DHCPACK(wlan0) 172.24.1.110 34:12:98:11:80:bd those-iPad
6 月 13 日 13:19:44 dnsmasq-dhcp[499]: DHCPDISCOVER(wlan0) d4:97:32:61:4f:73
6 月 13 日 13:19:44 dnsmasq-dhcp[499]: DHCPOFFER(wlan0) 172.24.1.82 d4:97:0b:61:4f:23
6 月 13 日 13:19:44 dnsmasq-dhcp[499]: DHCPREQUEST(wlan0) 172.24.1.82 d4:97:9f:61:4f:73
6月13日 13:19:44 dnsmasq-dhcp[499]:DHCPACK(wlan0)172.24.1.82 d4:97:0b:23:4f:73 android-ef9f423f7ecaca3c

在路由器中

这样我们每次解析日志就可以看到最新的MAC地址了。

但是我们不用每次都解析这么长的文件就能知道客户端 mac 是什么吗?这会拖累 CPU。

谢谢你!


更新

我找到了另一个包含它的地方

cat /var/lib/misc/dnsmasq.leases

它仍然是一个文件。还是每次我都必须解析该文件?

答案1

在 dnsmasq 的手册页中,有一个选项说

-l, --dhcp-leasefile=<path>
    Use the specified file to store DHCP lease information.

因此,您可以使用文件来记录它。 文件的格式为:

 946689575 00:00:00:00:00:05 192.168.1.155 wdt 01:00:00:00:00:00:05
 946689522 00:00:00:00:00:04 192.168.1.237 * 01:00:00:00:00:00:04
 946689351 00:0f:b0:3a:b5:0b 192.168.1.208 colinux *
 946689493 02:0f:b0:3a:b5:0b 192.168.1.199 * 01:02:0f:b0:3a:b5:0b

每行字段:

 1) Time of lease expiry, in epoch time (seconds since 1970). BTW you
 seem to be living in the past: most of us are well past 1000000000
 seconds by now :-) . There are compile time options in dnsmasq which
 convert this field to be remaining lease time (in seconds) or, in the
 most recent releases, total lease renewal time.

 2) MAC address.

 3) IP address.

 4) Computer name, if known. This is always unqualified (no domain part)

 5) Client-ID, if known. The client-ID is used as the computer's
 unique-ID in preference to the MAC address, if it's available. Some DHCP
 clients provide it, and some don't. The ones that do normally derive it
 from the MAC address unless explicity configured, but it could be
 something like a serial number, which would protect a computer from
 losing its identify if the network interface were replaced.

线条的顺序没有任何意义,并且会随着时间而改变。

相关内容