2016-06-28 111 views
2

我想編寫一個批處理文件獲取IP,這給了我一個IP回來,但我只知道MAC地址只知道MAC地址

arp -a 

不會爲我工作,因爲我從來沒有ping通該IP之前。我想在網絡中搜索它,只需知道MAC地址即可。

信息:IP是靜態的。

回答

2
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。

+0

我不知道這是否是最終解決方案。我可以明天告訴這個希望。但現在我有一個問題:第一個命令遍歷所有內容並將其保存在.txt文檔中。這樣做,我可以循環通過ARP表,或更好地不?爲什麼? – JetStream

2

編輯:剛剛意識到你在哪裏在Windows上。令人遺憾的是,在Windows上使用braodcast地址沒有本地方式,但您可以使用this answerFOR /L %i in (1,1,255) do @ping -n 1 192.168.1.%i | find "Reply"中的技巧。它似乎超級慢。

上一個答案在下方。


據我所知,你必須填寫你的ARP緩存來做你想做的。
This answer是你需要的。

正如帖子裏說,你可以:

  • 平通過Ping你的廣播地址你的局域網的所有主機(ping -b -c1 192.168.1.255,通過實際的廣播地址替換IP)
  • fping您的整個網絡(fping -a -g 192.168.1.0/24您實際使用的網絡掩碼替換)
  • NMAP網絡(nmap -sP 192.168.1.0/24
  • NBTSCAN(僅限Windows主機,nbtscan 192.168.1.0/24

然後在你的ARP緩存中查找。

0

我不是一個批處理用戶,所以我不知道命令,但我知道這樣做的方式是發送廣播ping請求到我們的網絡,並檢查從使用wireshark回覆的mac地址。

0

我記得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 
2

假設,你的子網是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 

編輯找到一種方法來加速這一過程。