다음은이 배치 스크립트입니다. 적어도 하나는 도움이되기를 바랍니다. 배치 파일을 원하는 경우
@ECHO OFF
::Lookup.bat
::http://www.computing.net/answers/programming/ip-by-hostname/25313.html
::Takes input file of hostnames and creates csv file with hostnames and IP addresses.
::Gets IP's using nslookup
:: Output in file hostnames.csv in current folder
if "%1"=="" goto :Syntax
SET SCRIPTPATH=%~p0
CD %SCRIPTPATH%
del hostnames.csv
for /f %%e in (%1) do call :LOOKUP %%e
echo Done!!!
goto :EOF
:LOOKUP
SET HOST1=%1
FOR /F "skip=4 tokens=2 delims=:" %%A IN ('2^>NUL nslookup %1') DO (ECHO %1,%%A>>%SCRIPTPATH%hostnames.csv)
GOTO :EOF
:Syntax
echo.
echo Syntax:
echo.
echo %0 ^<FileName^>
echo.
echo where ^<FileName^> is a file containing a list of hostnames.
echo.
echo The batch file will return the results to file hostnames.csv in current folder
goto :EOF
@echo off
::gethostname.bat
::Takes input file of IP addresses and creates csv file with IP address and hostnames.
::Gets hostnames using netBIOS, which is usually accurate. If no info avail from
::netBIOS, then use nslookup. Plenty of debug statements in screen output. :)
:: Output in file C:\TEMP\ip-resolved.csv
if "%1"=="" goto :Syntax
SET SCRIPTPATH=%~p0
CD %SCRIPTPATH%
echo ip,hostname,power>C:\TEMP\ip-resolved.csv
for /f %%e in (%1) do call :PING-NBT %%e
echo Done!!!
goto :EOF
:PING-NBT
set ipaddress=%1
set host1=
echo.
echo ***Pinging %ipaddress%
SET ON=0
PING -n 1 %1 | find /i "Reply from" >nul && SET ON=1
echo Just parsed ping reply... host is %ON%
REM Next line skips netBIOS check if host is offline
IF "%ON%"=="0" GOTO :LOOKUP %ipaddress% %ON%
echo Proceeding to nbtstat with host %on%
REM The next lines check netBIOS name.
echo nbt1-start
for /f %%i in ('nbtstat -a %1^|find "<20>"') do @set host1=%%i
echo nbt=%host1% power=%ON%
REM If there isn't a NetBIOS name, then skips to nslookup section.
REM echo %2
if "%host1%"=="" goto :LOOKUP %1 %ON%
ECHO %ipaddress%,%host1%,%ON% >> C:\TEMP\ip-resolved.csv
echo nbt2-end
goto :EOF
:LOOKUP
echo nslookup1-start
for /f "tokens=2" %%i in ('nslookup %1^|find "Name:"') do @set host1=%%i
echo nslookup=%host1% power=%2
REM Next line=if host var
rem if not "%host1%"=="%1" goto :EOF
ECHO %ipaddress%,%host1%,%2 >>C:\TEMP\ip-resolved.csv
set host1=
echo nslookup2-end
goto :EOF
:Syntax
echo.
echo Syntax:
echo.
echo %0 ^<FileName^>
echo.
echo where ^<FileName^> is a file containing a list of IP addresses to
echo which we need the hostname.
echo.
echo The batch file will return the results via a file
echo C:\TEMP\ip-resolved.csv
goto :EOF
당신은 혼자의 VBScript에서 API를 호출 어차피 그것이 무엇 NETBIOS 역방향 조회에 올 때 nslookup을 –
nslookup을 호출하는 것은 매우 유용하지 않습니다에 대한. 수천 명의 클라이언트가있는 거대한 LAN 환경에서 NetBIOS 역방향 조회가 필요합니다. 'NBTSTAT -A'는 유용하지만 양쪽 결과가 비슷한지 확실하지 않습니다. 아마도 내부적으로 gethostbyaddr API를 사용하고있을 수도 있습니다 (또는 다른 방법 일 수도 있습니다). 역순 조회를위한 perl 스크립트를 실행하면 항상 최상의 결과를 얻을 수 있으며 NBTSTAT 출력은 너무 복잡해져 NETBIOS 조회가 실패 할 경우 DNS를 역전시키지 않습니다. – Benny