T
tonysathre
I need to add hostname resolution to my getMAC.bat script. Right now it
only works with IP addresses. I found this:
http://www.robvanderwoude.com/files/hostname_nt.txt script that gets
the hostname for a given IP, and ECHO's it to stdouot. How can I
integrate that that for loop into my existing script?
@echo off
set ip= %1
if /i "%1" == "?" goto help
if /i "%1" == "/?" goto help
if /i "%1" == "-h" goto help
if /i "%1" == "--help" goto help
if /i "%1" == "/h" goto help
if /i "%1" == "" (goto start
)else goto auto
:start
cls
echo.
echo.
echo.
echo Clearing ARP Cache . . .
netsh interface ip delete arpcache
echo Enter IP address of remote computer:
set /p ip=
if %ip% == exit goto end
if %ip% == quit goto end
for %%i in (%ip%) do (ping -n 1 %%i > NUL
if errorlevel 1 goto fail
cls
echo.
echo IP Address MAC Address Type
echo ___________________________________________________
echo.
arp -a | findstr "%%i"
goto eof
)
echo.
:auto
ping -n 1 %1 > NUL
if errorlevel 1 goto fail2
cls
echo.
echo IP Address MAC Address Type
echo ___________________________________________________
echo.
arp -a | findstr "%1"
echo.
goto end
:fail
echo.
cls
echo.
echo Host not found, or not alive
echo.
goto eof
:fail2
echo.
cls
echo.
echo Host not found, or not alive
echo.
goto end
:eof
echo.
pause
goto start
:help
@echo off
echo.
echo DESCRIPTION:
echo Gets the MAC address for a remote computer, given it's IP address.
echo.
echo USAGE:
echo getmac [ip_address]
echo.
echo PARAMETERS:
echo
echo To use interactively, run getMAC with no parameters.
echo.
echo EXAMPLE:
echo.
echo getmac 192.168.1.1
:end
title Command Prompt
Thanks,
Tony
only works with IP addresses. I found this:
http://www.robvanderwoude.com/files/hostname_nt.txt script that gets
the hostname for a given IP, and ECHO's it to stdouot. How can I
integrate that that for loop into my existing script?
@echo off
set ip= %1
if /i "%1" == "?" goto help
if /i "%1" == "/?" goto help
if /i "%1" == "-h" goto help
if /i "%1" == "--help" goto help
if /i "%1" == "/h" goto help
if /i "%1" == "" (goto start
)else goto auto
:start
cls
echo.
echo.
echo.
echo Clearing ARP Cache . . .
netsh interface ip delete arpcache
echo Enter IP address of remote computer:
set /p ip=
if %ip% == exit goto end
if %ip% == quit goto end
for %%i in (%ip%) do (ping -n 1 %%i > NUL
if errorlevel 1 goto fail
cls
echo.
echo IP Address MAC Address Type
echo ___________________________________________________
echo.
arp -a | findstr "%%i"
goto eof
)
echo.
:auto
ping -n 1 %1 > NUL
if errorlevel 1 goto fail2
cls
echo.
echo IP Address MAC Address Type
echo ___________________________________________________
echo.
arp -a | findstr "%1"
echo.
goto end
:fail
echo.
cls
echo.
echo Host not found, or not alive
echo.
goto eof
:fail2
echo.
cls
echo.
echo Host not found, or not alive
echo.
goto end
:eof
echo.
pause
goto start
:help
@echo off
echo.
echo DESCRIPTION:
echo Gets the MAC address for a remote computer, given it's IP address.
echo.
echo USAGE:
echo getmac [ip_address]
echo.
echo PARAMETERS:
echo
echo To use interactively, run getMAC with no parameters.
echo.
echo EXAMPLE:
echo.
echo getmac 192.168.1.1
:end
title Command Prompt
Thanks,
Tony