RosettaCodeData/Task/DNS-query/Batch-File/dns-query.bat

39 lines
1,023 B
Batchfile
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
:: DNS Query Task from Rosetta Code Wiki
:: Batch File Implementation
2015-11-18 06:14:39 +00:00
2016-12-05 22:15:40 +01:00
@echo off
2015-11-18 06:14:39 +00:00
2016-12-05 22:15:40 +01:00
set "domain=www.kame.net"
echo DOMAIN: "%domain%"
2017-09-23 10:01:46 +02:00
echo(
2016-12-05 22:15:40 +01:00
call :DNS_Lookup "%domain%"
2015-11-18 06:14:39 +00:00
pause
2016-12-05 22:15:40 +01:00
exit /b
::Main Procedure
2017-09-23 10:01:46 +02:00
::Uses NSLOOKUP Command. Also uses a dirty "parsing" to detect IP addresses.
2016-12-05 22:15:40 +01:00
:DNS_Lookup [domain]
2017-09-23 10:01:46 +02:00
::Define Variables and the TAB Character
set "dom=%~1"
2016-12-05 22:15:40 +01:00
set "record="
2017-09-23 10:01:46 +02:00
set "reccnt=0"
for /f "delims=" %%T in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo(0x09"') do set "TAB=%%T"
setlocal enabledelayedexpansion
for /f "tokens=1* delims=:" %%x in ('nslookup "!dom!" 2^>nul') do (
set "line=%%x"
if /i "!line:~0,4!"=="Name" set "record=yes"
if /i "!line:~0,5!"=="Alias" set "record="
if "!record!"=="yes" (
set /a reccnt+=1
if "%%y"=="" (set "catch_!reccnt!=%%x") else (set "catch_!reccnt!=%%x:%%y")
)
)
for /l %%c in (1,1,%reccnt%) do (
if /i "!catch_%%c:~0,7!"=="Address" echo(!catch_%%c:*s: =!
if /i "!catch_%%c:~0,1!"=="%TAB%" echo(!catch_%%c:%TAB% =!
2016-12-05 22:15:40 +01:00
)
2017-09-23 10:01:46 +02:00
endlocal
2016-12-05 22:15:40 +01:00
goto :EOF