windows 从 MAC 地址获取 IP。arp -a 不显示设备

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25404485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:39:29  来源:igfitidea点击:

Get IP from MAC address. arp -a not showing device

windowsbatch-filenetworkingcommand-linearp

提问by SouPress

I'm trying to write a batch file that's supposed to find the dynamically assigned IP of my Android phone when it's connected to the network (Tenda WiFi router).

我正在尝试编写一个批处理文件,当它连接到网络(腾达 WiFi 路由器)时,它应该可以找到我的 Android 手机的动态分配的 IP。

So I'm trying arp -aand searching for my phone's MAC address so I can get its IP from the table.

所以我正在尝试arp -a搜索我手机的 MAC 地址,以便我可以从表中获取它的 IP。

C:\Users\Leeroy>arp -a

Interface: 192.168.0.100 --- 0xb
  Internet Address      Physical Address      Type
  192.168.0.1           c8-3a-35-35-f6-68     dynamic
  192.168.0.255         ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.255.250       01-00-5e-7f-ff-fa     static
  255.255.255.255       ff-ff-ff-ff-ff-ff     static

The problem is it doesn't show up in the table! I tried ping 192.168.0.255but it still doesn't show up. I tried requesting 192.168.0.100 (IP of my desktop PC) from the phone's browser, and that sure enough puts the phone on the radar. But I don't have the option to manually do that everytime I want it to appear in the arp table.

问题是它没有显示在表格中!我试过了,ping 192.168.0.255但它仍然没有出现。我尝试从手机的浏览器请求 192.168.0.100(我的台式电脑的 IP),这确实让手机受到关注。但是每次我希望它出现在 arp 表中时,我都没有选择手动执行此操作。

How do I get the Android phone to appear in the arp table (without doing anything from it besides connecting to WiFi)?

如何让 Android 手机出现在 arp 表中(除了连​​接到 WiFi 之外,什么都不做)?

采纳答案by PaddyD

I have tried this and it works:

我试过这个,它的工作原理:

for /L %N in (1,1,254) do start /b ping -n 1 -w 200 192.168.0.%N

provided the phone has ICMP enabled, you should have no problem.

只要手机启用了ICMP,你应该没有问题。

回答by Aloiso Junior

If you want find IP from MAC do this

如果您想从 MAC 中查找 IP,请执行此操作

$  arp -n | grep -w -i 'YOUR-MAC' | awk '{print }'

Note you must replace YOUR-MAC, with your mac address, keep single quotes

注意你必须用你的mac地址替换YOUR-MAC,保留单引号

Now, if you want find MAC Address from some IP Try this:

现在,如果您想从某个 IP 中查找 MAC 地址,请尝试以下操作:

$  arp -n | grep -w -i 'YOUR-IP' | awk '{print }'

Enjoy!

享受!

回答by M.S. Arun

This Batch Code will fetch the below,

此批处理代码将获取以下内容,

  1. PC Name
  2. IP Address
  3. MAC Address
  4. Computer Description(If Available)
  1. 电脑名称
  2. IP地址
  3. MAC地址
  4. 计算机描述(如果有)

Please save the below code in anyname.batformat and run it. It will output the results in a separate text file.

请将以下代码保存为anyname.bat格式并运行它。它将在单独的文本文件中输出结果。

    :: This Windows Batch(CMD) File fetches All the Details of the Nearby PC's of Same VLAN (Upto 254 host's).
    :: Windows OS (CMD)
    :: Author : [M.S.Arun][1]

    :: #****************************************************************** Start of Script ********************************************************************#

    @echo off
    title Remote PC Details Fetching Script(PC Name / IP's / Computer Description)
    echo. > %cd%\PC_Details_Temp.txt
    echo Remote PC Details Fetching Script (PC Name / IP's / Computer Description) details of the Nearby PC's of Same VLAN.(Upto 254 Hosts)
    echo.
    set /p input_ip="Please Enter the IP Range(Eg:192.168.1) :  " && echo
    set /p input_ip_start="Please Enter Start IP Range(Eg:1) :  " && echo
    set /p input_ip_end="Please Enter End IP Range(Eg:254) :  " && echo
    echo. >> %cd%\PC_Details_Temp.txt
    @echo on
    for /l %%i in (%input_ip_start%, 1, %input_ip_end%) do nbtstat -a %input_ip%.%%i | findstr /c:"MAC" /c:"<00>" | findstr /c:"MAC" /c:"UNIQUE" >> %cd%\PC_Details_Temp.txt && echo     IP Address  = %input_ip%.%%i >> %cd%\PC_Details_Temp.txt
    @echo off
    echo. > %cd%\PC_Details_Logs.txt
    echo. > %cd%\PC_Details_Logs.txt
    echo This Batch Script fetches All the Details of the Nearby PC's of Same VLAN.(Starting from 1 to 254 host's) >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo PC Host Name: >> %cd%\PC_Details_Logs.txt
    find "UNIQUE" PC_Details_Temp.txt >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo PC IP Address: >> %cd%\PC_Details_Logs.txt
    find "IP" PC_Details_Temp.txt >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo PC MAC Address: >> %cd%\PC_Details_Logs.txt
    find "MAC" PC_Details_Temp.txt >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo PC Seat No's. and Vnet No's: >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    net view /all >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    echo. >> %cd%\PC_Details_Logs.txt
    arp -a >> %cd%\PC_Details_Logs.txt
    :: del %cd%\PC_Details_Temp.txt
    echo.
    echo Completed Successfully..!
    echo.
    pause

    :: #****************************************************************** End of Script ********************************************************************#

Screenshots For References, enter image description here

截图供参考, 在此处输入图片说明

enter image description here

在此处输入图片说明

回答by eaz

M.S.Arun'sanswer is close to the best. I had this problem for retrieveing some virtual machines IP address for which all I had was the MAC address. A lot of answers like M.S.Aruns's all over stackoverflow and elsewhere, but nobody explains them, nor explains the solution correctly (IMHO).

MSArun 的答案接近最好。我在检索一些虚拟机 IP 地址时遇到了这个问题,而我所拥有的只是 MAC 地址。很多答案都像 MSAruns 在 stackoverflow 和其他地方一样,但没有人解释它们,也没有正确解释解决方案(恕我直言)。

I tried the technique of pinging all subnet and then do an arp command. The problem was my IP range had 60k+ possible IP address and after scanning all of them (which was not so simple, and really ugly with the start command) the arp table was really poorly populated... Btw it was taking like 30 secs, even while trying with "start ping". I eventually figured out that the arp, being a cache table, flushes itself periodically, which is why this method rarely succeeded.

我尝试了 ping 所有子网的技术,然后执行 arp 命令。问题是我的 IP 范围有 60k+ 可能的 IP 地址,并且在扫描所有这些之后(这不是那么简单,并且使用 start 命令非常丑陋)arp 表的填充量真的很差......顺便说一句,它花了大约 30 秒,即使在尝试“开始 ping”时也是如此。我最终发现作为缓存表的 arp 会定期刷新自身,这就是这种方法很少成功的原因。

The solution is to ping all subnet, but after each ping perform an arp command to see if the IP matches your MAC address, which ensures you not to loose information because of the cache nature of the arp tables. To make it proper, I implemented this in Java; the isReachable() method is really cleaner and there are no cmd prompts spawning everywhere on my screen. Moreover, the 60k+ range of IPs scanning takes up to 10sec using Java threads. I think it's a more secure way than batch scripting...

解决方案是 ping 所有子网,但在每次 ping 后执行 arp 命令以查看 IP 是否与您的 MAC 地址匹配,这可确保您不会因为 arp 表的缓存性质而丢失信息。为了使它正确,我用 Java 实现了它;isReachable() 方法确实更简洁,而且我的屏幕上没有任何 cmd 提示出现。此外,使用 Java 线程扫描 60k+ 范围的 IP 最多需要 10 秒。我认为这是比批处理脚本更安全的方式......

See threadedScan() method herewhich takes in an array of IPs and looks for the MAC address.

请参阅此处的 threadedScan() 方法,方法接受 IP 数组并查找 MAC 地址。

Hope this can help ;)

希望这可以帮助;)

回答by Yash Ojha

this might work

这可能有效

netstat -n  

or

或者

ipconfig /all