[英]Echo DNS and Alternative DNS using command line/ batch
I have been using a for loop
with findstr
to echo
specific lines from ipconfig/all
.我一直在使用带有
findstr
的for loop
来回显来自echo
ipconfig/all
的特定行。 For example例如
for /f "tokens=*" %a in ('ipconfig/all ^| findstr "#DNS Servers"') do (echo %a)
[double percentage sign to use within batch file] for /f "tokens=*" %a in ('ipconfig/all ^| findstr "#DNS Servers"') do (echo %a)
[在批处理文件中使用双百分号]
This will echo out the DNS Servers line
but how to get the Alternate address that is beneath that in ipconfig/all
There nothing in that line to findstr
to help isolate it.这将回显
DNS Servers line
,但如何获取ipconfig/all
中该行下方的备用地址该行中没有任何findstr
可以帮助隔离它。 Is there a way to do this?有没有办法做到这一点?
Here is the relevant ipconfig/all output. I am looking for YYYY
这里是相关的ipconfig/all output 我在找
YYYY
Windows IP Configuration
Host Name . . . . . . . . . . . . : XXXX
Primary Dns Suffix . . . . . . . : XXXX
Node Type . . . . . . . . . . . . : XXXX
IP Routing Enabled. . . . . . . . : XXXX
WINS Proxy Enabled. . . . . . . . : XXXX
DNS Suffix Search List. . . . . . : XXXX
Ethernet adapter Ethernet 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel Adapter #2
Physical Address. . . . . . . . . : XXXX
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel
Physical Address. . . . . . . . . : XXXX
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : XXXX(Preferred)
IPv4 Address. . . . . . . . . . . : XXXX(Preferred)
Subnet Mask . . . . . . . . . . . : XXXX
Default Gateway . . . . . . . . . : XXXX
DHCPv6 IAID . . . . . . . . . . . : XXXX
DHCPv6 Client DUID. . . . . . . . : XXXX
DNS Servers . . . . . . . . . . . : XXXX
YYYY
NetBIOS over Tcpip. . . . . . . . : Enabled
I want to try this in batch because it is to use at the end of anther batch program.我想批量尝试这个,因为它是在另一个批处理程序的末尾使用。
It's surprisingly easy in your case:在您的情况下,这非常简单:
ipconfig /all |findstr /bc:" DNS-Server" /c:" "
Note: if you have more than one.network adapter, you get the DNS-Server(s) (both IPv4 and IPv6) of all of them without any hint, which belongs to which.注意:如果您有多个网络适配器,您会在没有任何提示的情况下获得所有这些适配器的 DNS 服务器(IPv4 和 IPv6),哪个属于哪个。
Note: the output of ipconfig
is language-dependent.注意:
ipconfig
的 output 是语言相关的。 You probably have to adapt the string DNS-Server
to your actual output.您可能必须将字符串
DNS-Server
调整为实际的 output。
If you want the "alternative" DNS-Server only:如果您只想要“替代”DNS 服务器:
ipconfig /all |findstr /bc:" "
( There nothing in that line to findstr to help isolate it.
: yes, there is. It's the only line(s) that starts with more than three spaces. findstr /b
matches pattern if at the b eginning of a line) (
There nothing in that line to findstr to help isolate it.
:是的,有。它是唯一以三个以上空格开头的行。如果在一行的开头, findstr /b
匹配模式)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.