Linux
如何動態查看 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 個-iPad
Jun 13 13:19:44 dnsmasq-dhcp$$ 499 $$: DHCPDISCOVER(wlan0) d4:97:32:61:4f:73
Jun 13 13:19:44 dnsmasq-dhcp$$ 499 $$: DHCPOFFER(wlan0) 172.24.1.82 d4:97:0b:61:4f:23
Jun 13 13:19:44 dnsmasq-dhcp$$ 499 $$: DHCPREQUEST(wlan0) 172.24.1.82 d4:97:9f:61:4f:73
Jun 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
仍然是一個文件。還是我每次都必須解析文件?
在 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.
行的順序沒有意義,並且會隨著時間而改變。