JSI Tip 8389. Resolve script returns the IP Address, DNS name, and NetBIOS name of a computer.

Jerold Schulman

August 17, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Jack Kress has provided Resolve.bat to return the IP Address, DNS name, and NetBIOS name of a computer.

When I type resolve jsi001, I receive:

IP ADDRESS =   216.144.1.25DNS NAME =     jsi001.jsiinc.comNETBIOS NAME = JSI001

When I type resolve 216.144.1.25, I receive:

IP ADDRESS =   216.144.1.25DNS NAME =     jsi001.jsiinc.comNETBIOS NAME = JSI001

When I type resolve jsi001.jsiinc.com, I receive:

IP ADDRESS =   216.144.1.25DNS NAME =     jsi001.jsiinc.comNETBIOS NAME = JSI001

To process the returned information in a script, you could use:

for /f "Tokens=1,2* Delims
" %%a in ('resolve jsi001') do ( if "%%a" EQU "IP" set IP=%%c if "%%a" EQU "DNS" set DNS=%%c if "%%a" EQU "NETBIOS" set NETBIOS=%%c)

Resolve.bat contains:

@ECHO Off::Returns a IP, NETBIOS and DNS name from a IP, NETBIOS or DNS name being passed in.::Syntax: RESOLVE 192.168.1.1::Syntax: RESOLVE SERVERNAME::Syntax: RESOLVE SRVR.DOMAIN.COM::Jack Kress - 2/26/04:: v3SETLOCALSET SCRIPTNAME=%~n0IF "%1""" ECHO Incorrect Syntax - use: %SCRIPTNAME% NETBIOSNAME && GOTO :EOFFOR /F "tokens=3delims=: " %%I IN ('PING -n 1 %1 ^| FIND "Reply from"') DO ( SET IP=%%I FOR /F "tokens=2 delims=:" %%J IN ('NSLOOKUP %%I ^| FIND "Name:"') DO SET DNS=%%J FOR /F %%K IN ('NBTSTAT -A %%I ^| FIND "  UNIQUE"') DO SET NETBIO=%%K)IF NOT DEFINED IP @ECHO %1 is invalid or NETWORK error occurred. && GOTO :EOF@ECHO.@ECHO IP ADDRESS =   %IP%IF NOT DEFINED DNS @ECHO %1 - invalid DNS name or DNS error occurred. && GOTO :EOF@ECHO DNS NAME = %DNS%IF NOT DEFINED NETBIO @ECHO %1 - invalid NETBIOS name or WINS error occurred. && GOTO :EOF@ECHO NETBIOS NAME = %NETBIO%ENDLOCAL



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like