我可以从已知的MAC地址确定当前IP吗? [英] Can I determine the current IP from a known MAC Address?

查看:176
本文介绍了我可以从已知的MAC地址确定当前IP吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个shell脚本,该脚本使用etherwake唤醒本地网络上的计算机. 机器醒来后,我不确定IP地址.

I have a shell script which uses etherwake to wake up a machine on my local network. After the machine is awake, I'm not sure of the IP address.

在尝试回答我自己的问题时,我想到了:

While trying to answer my own question I came up with:

ip=$(ping -c 1 hostname | head -1 | awk '{print $3}' | sed 's/[()]//g')

此解决方案规定,我知道远程计算机的主机名,该主机名并不繁琐.

This solution stipulates that I know the hostname of the remote machine, which isn't so onerous.

如果我只知道MAC地址,是否可以获取IP?

Is there a way to get the IP if all I know is the MAC address?

推荐答案

我认为没有单个命令可以执行此操作.一种破解方法是在子网上执行ping扫描或广播ping,然后在arp表中查询MAC地址的IP地址.显然不是理想的解决方案.示例:

I don't think there is a single command to do this. One hack would be to do a ping scan or a broadcast ping on the subnet and then query the arp table for the IP address of the MAC address. Obviously not an ideal solution. Example:

nmap -sP 192.168.1.0/24 >/dev/null && arp -an | grep <mac address here> | awk '{print $2}' | sed 's/[()]//g'

在此,nmap将执行ping扫描并填充您的arp缓存.扫描完成后,可以使用arp命令打印arp表,然后使用grep/awk提取IP地址.您可以尝试用广播ping代替nmap,但这可能不那么可靠.

Here nmap will do a ping scan and populate your arp cache. Once the scan is done, the arp command can be used to print the arp table and then you pull out the IP address with grep/awk. You could try replacing nmap with a broadcast ping, but that probably isn't as reliable.

这篇关于我可以从已知的MAC地址确定当前IP吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆