I have scripted GetIpByName.bat to return the IP address of a computer on your network or on the internet.
The syntax for using GetIpByName.bat is:
call GetIpByName Name IP
Where:
Name is the host name, like JSI001, or JSI001.JSIINC.COM, or WWW.JSIFAQ.COM. IP is a call directed environment variable that will contain the IP address. If the Name is NOT FOUND, IP will be set to NONE.NOTE: GetIpByName.bat uses Win32_PingStatus, only available on Windows XP, Windows Server 2003, and later.
GetIpByName.bat contains:
@echo off if \{%2\}==\{\} @echo GetIpByName Name IP&goto :EOF if exist "%TEMP%\GetIpByName.vbs" goto getip @echo.On Error Resume Next>"%TEMP%\GetIpByName.vbs" @echo.Dim objArgs>>"%TEMP%\GetIpByName.vbs" @echo.Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")>>"%TEMP%\GetIpByName.vbs" @echo.Set objArgs = Wscript.Arguments>>"%TEMP%\GetIpByName.vbs" @echo.Set iPA = objWMIService.ExecQuery _>>"%TEMP%\GetIpByName.vbs" @echo. ("Select * from Win32_PingStatus " ^& "Where Address = '" ^& objArgs(0) ^& "'")>>"%TEMP%\GetIpByName.vbs" @echo. For Each iP In iPA>>"%TEMP%\GetIpByName.vbs" @echo. WScript.Echo iP.ProtocolAddress>>"%TEMP%\GetIpByName.vbs" @echo. Next>>"%TEMP%\GetIpByName.vbs" :getip set %2=NONE for /f "Tokens=*" %%i in ('cscript //nologo "%TEMP%\GetIpByName.vbs" %1') do set %2=%%i
0 comments
Hide comments