Need to get hostname added to batch code

November 14, 2010 at 09:03:29
Specs: Windows XP
This is what I have on the main loop, I have added the -a option to the ping comand to resolve the hostname, this loop already gets me the IP, and MAC address, but I need to add the hostname to the output file, I need to add an additional variable to the loop without interfering w/the variables for the MAC and IP.
Thanks

:loop
Set CI=%CA%.%CB%.%CC%.%CD%
If [%CZ%]==[0] Echo %Time%: %CI% ...
Ping -a -n 2 %CI% -w 150 >nul
For /F "tokens=1,2 skip=3" %%i in ('arp -a %CI%') do Call :HostInfo %%i %%j
If [%CI%]==[%EI%] goto loopend
If [%CD%]==[255] (Set CD=0) Else (Set /A CD=CD+1 & Goto loop)
If [%CC%]==[255] (Set CC=0) Else (Set /A CC=CC+1 & Goto loop)
If [%CB%]==[255] (Set CB=0) Else (Set /A CB=CB+1 & Goto loop)
If [%CA%]==[255] (goto loopend) Else (Set /A CA=CA+1 & Goto loop)
goto loop

:loopend

goto end

:HostInfo
If [%2]==[00-00-00-00-00-00] Goto EndHostInfo
Echo IP: %1 MAC: %2 Hostname:
:EndHostInfo
Goto :EOF


See More: Need to get hostname added to batch code

Report •


#1
November 19, 2010 at 10:19:06


:HostInfo
If [%2]==[00-00-00-00-00-00] Goto EndHostInfo
Echo IP: %1 MAC: %2 Hostname: %computername%
:EndHostInfo
Goto :EOF

%Computername% is a system varible which will print the computername.

Subhash Chandra.


Report •

#2
November 21, 2010 at 14:54:45
Thank you Subhash, however the variable %computername% only prints the name of the host from which the program is running. I need the hostname of the machines I'm pinging. Thanks,

Report •

#3
November 23, 2010 at 11:35:34
I have come up w/these solutions to add it to the code, but still is not working:

For /F "tokens=2,3 delims= " %%A IN ('Ping -a -n 2 %CI% -w 150 >nul') Do If "%%B"=="[%CI%]" Set H=%%A

Or maybe use:
Nslookup %CI% | Findstr /X %3 >

but how do I rerouted to a variable that I can display? Maybe someone can point me in the right direction. Thanks.


Report •
Related Solutions


Ask Question