我想编写一个批处理文件获取IP,这给了我一个IP回来,但我只知道MAC地址只知道MAC地址
arp -a
不会为我工作,因为我从来没有ping通该IP之前。我想在网络中搜索它,只需知道MAC地址即可。
信息:IP是静态的。
我想编写一个批处理文件获取IP,这给了我一个IP回来,但我只知道MAC地址只知道MAC地址
arp -a
不会为我工作,因为我从来没有ping通该IP之前。我想在网络中搜索它,只需知道MAC地址即可。
信息:IP是静态的。
for /f "skip=3 delims=\" %%A in ('net view ^| findstr /v /C:"The command completed successfully"') do Echo %%A >> "%userprofile%\desktop\computerlist.txt"
列表已打开计算机。
wmic /node:@computerlist.txt nicconfig where macaddress='whatever:whatever:etc' get ipaddress /format:htable
要为指定MACADDRESS
wmic /node:@computerlist.txt nicconfig get ipaddress /format:htable
获得IP来获取ip地址的计算机上的所有MACAddresses。
编辑:刚刚意识到你在哪里在Windows上。令人遗憾的是,在Windows上使用braodcast地址没有本地方式,但您可以使用this answer:FOR /L %i in (1,1,255) do @ping -n 1 192.168.1.%i | find "Reply"
中的技巧。它似乎超级慢。
上一个答案在下方。
据我所知,你必须填写你的ARP缓存来做你想做的。
This answer是你需要的。
正如帖子里说,你可以:
ping -b -c1 192.168.1.255
,通过实际的广播地址替换IP)fping -a -g 192.168.1.0/24
您实际使用的网络掩码替换)nmap -sP 192.168.1.0/24
)nbtscan 192.168.1.0/24
)然后在你的ARP缓存中查找。
我不是一个批处理用户,所以我不知道命令,但我知道这样做的方式是发送广播ping请求到我们的网络,并检查从使用wireshark回复的mac地址。
我记得sachadee张贴了这个代码SCANIP-MAC.bat
@echo off
Title Scan for IP and MAC Adress on LAN
mode con cols=60 lines=20
Color A
set ip=192.168.1.1
set debut=1
set fin=10
if exist ping.txt (del ping.txt)
if exist ping2.txt (del ping2.txt)
if exist ping3.txt (del ping3.txt)
if exist ping4.txt (del ping4.txt)
for /L %%i in (%debut%,1,%fin%) do (echo Recherche de la machine : %ip:~0,9%.%%i
for /f "tokens=5 delims= " %%f in ('ping -4 -n 1 %ip:~0,9%.%%i ^|find /i "32"') do (echo %%f >> ping.txt
)
for /f "tokens=1 delims= " %%k in ('Type ping.txt ^|findstr /i "19"') do echo %%k > ping2.txt
for /f %%l in (ping2.txt) do (arp -a %%l >> ping3.txt
)
)
Cmd /U /C Type ping3.txt > ping4.txt
Del ping.txt
Del ping2.txt
Del ping3.txt
Start ping4.txt
假设,你的子网是192.168.1。XXX
@echo off
REM clear arp cache (optional):
arp -d
REM ask everybody on the subnet for a response:
for /l %%a in (1,1,255) do start /b ping -n 2 -w 500 192.168.1.%%a >nul
REM wait for the processes to finish:
timeout 2 >nul
REM show the responses (with IP and MAC):
arp -a
当你发现IP,你可以尝试解析计算机名称:
ping -a -n 1 192.168.1.xxx
编辑找到一种方法来加速这一过程。
我不知道这是否是最终解决方案。我可以明天告诉这个希望。但现在我有一个问题:第一个命令遍历所有内容并将其保存在.txt文档中。这样做,我可以循环通过ARP表,或更好地不?为什么? – JetStream