如何在Linux中ping MAC地址 [英] How to ping MAC address in Linux
本文介绍了如何在Linux中ping MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想ping一个已知的MAC地址,我试图使用nmap:
I want to ping a known MAC address, I tried to use nmap:
sudo nmap -sP 192.168.15.1/24 | grep 20:64:32:3F:B1:A9
但在这种情况下它的ping全部为255 IP地址(从192.168.15.1到192.168.15.255)直到得到我的MAC地址,这需要很长时间大约4秒。
But in this case its ping all the 255 IP address (from 192.168.15.1 to 192.168.15.255) until get my MAC address, and that take a long time about 4 sec.!
有什么想法吗?
推荐答案
使速度更快的唯一方法是测试mac地址是否已经进入你的arp表
The only way to make it faster is to test if the mac address is already into your arp table
#!/bin/bash
# extract ip from local arp table
ip=$(arp | grep 20:64:32:3F:B1:A9 | awk ' { print $1 } ')
# found an ip tied to the mac address?
if [ ! -z $ip ]; then
# if found, do you want to ping it?
ping $ip
else
echo "Not found into local arp table. Trying another way..."
# wanna try your nmap strategy?
# sudo nmap -sP 192.168.15.1/24 | grep 20:64:32:3F:B1:A9
fi;
这篇关于如何在Linux中ping MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文