Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
331 views
in Technique[技术] by (71.8m points)

cmd - Parsing DNS info to .txt file

I need to get the DNS info, which can be found under ipconfig /all but when I try it using

SETLOCAL
(

FOR /f "tokens=1*delims=:" %%b IN ('ipconfig /all') DO (
 
FOR /f %%t IN ("%%b") DO (
  
If /i "%%t"=="DNS" ECHO %%c&GOTO done
 )

)
)> out.txt

it gives me the DNS suffix. Any suggestions on how I might actually get DNS servers? If I try with

If /i "%%t"=="DNS" ECHO %%c&GOTO done

then I end up with no info at all. I'm using a batch file and cmd

question from:https://stackoverflow.com/questions/65893346/parsing-dns-info-to-txt-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
@ECHO Off
SETLOCAL
set "dnsserverlines="
(
FOR /f "tokens=1*delims=:" %%b IN ('ipconfig /all') DO (
 FOR /f "tokens=1,2" %%t IN ("%%b") DO (
 IF DEFINED dnsserverlines IF "%%c" neq "" GOTO :EOF 
 IF DEFINED dnsserverlines IF "%%t" neq "0.0.0.0" ECHO  %%t 
 If /i "%%t%%u"=="DNSServers" ECHO %%c&set "dnsserverlines=Y"
 )
)
)> out.txt
GOTO :EOF

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...