How Can I get IP and MAC address for remote PCs over the network by batch file

Started by Abo-Zead, December 28, 2020, 08:16:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Abo-Zead

Hackoo
After a lot of searches, I found the below code


@ECHO OFF
For /f %%a in (hosts.txt) do (
     ping -n 1 %%a | for /f "tokens=1-4* delims=: " %%i in ('find "Reply"') do (
           nbtstat -a %%a | for /f "tokens=1-2 delims=^=" %%x in ('find "MAC Address"') do (
           echo [ %%a   :  %%k   :  %%y   ]>> Host_IP_MAC.txt
echo [ %%a   :  %%k   :  %%y   ]
           )
     )
)


and after testing I found it works only with all workstations working under WinXp only and the rest of the workstations working under Win7, 8, 8.1, and 10 doesn't work, so kindly help If you have an idea to fix this bug.

Koverland

I don't quite understand how you solved your problem? Like you, I have many different hostnames, but I do not know how to get information about all of them at once. Unfortunately, I do not understand the software part at all. This was done by my partner, who literally went on vacation two days ago. Therefore, I am literally at a dead end, I hope it will not be difficult for you to suggest a solution to my problem. I thought that I could somehow call all the hosts I needed using 192.168, but unfortunately I didn't succeed. So I stopped trying to do something by myself. Nowadays, literally any problem can be solved via the Internet, so I thought that my problem could also be solved.

Abo-Zead

Dear Koverland
Here is the mentioned code that i have it with the help of some good people here:

for /f %%a in ('type "Your_file"') do (
   set bHOSTUP=0
   ping -n 1 %%a -w 2000 |find "TTL=" > nul && set bHOSTUP=1
   IF !bHOSTUP! equ 1 (
      set g=%%a
      CALL :HOSTUP %%a
   ) else (
      set g=%%a
      CALL :HOSTDOWN %%a
   )
)
:HOSTUP
for /f "tokens=3 delims=," %%i in ('getmac /s %g% /v /nh /fo csv') do (
echo [%%a : %%~i] >>"Online MAC-Addresses.txt"

:HOSTDOWN
echo.[%g% : is Offline or not Exist]>>"Offline MAC-Addresses.txt"


And it works for me on windows 7 and latter
just insert your file name and be sure that the mentioned file in the same directory

Abo-Zead

Dear Koverland,

I hope my previous code helps you and I'm so sorry to see your reply too late as I didn't open the site for a while
and you should ask Hackoo for more help after you make your best efforts as he's from the best people here.