batch-file - 仅当适配器当前设置为静态分配时才设置 dns 地址的批处理文件
问题描述
第一篇文章,编码新手。如果适配器 dhcp enabled 设置设置为 No,我正在寻找一个批处理文件来设置 dns 服务器。我实际上有这个工作但它有限。目前,如果它看到任何启用了 dhcp 的适配器为 no,那么它将在所有 nics 上设置 dns 服务器。我还需要它来检查是否未启用 dhcp 以及 nic 是否不是环回适配器。如果 dhcp enabled = no 和 ip address <> 127.0.0.1 然后设置 dns 服务器地址。
这是我目前拥有的...
@echo off
SET _DHCP=Maybe
For /f "tokens=2 delims=:" %%a in ('netsh interface ip show addresses ^|FIND "DHCP Enabled"') DO SET _DHCP=%%a
IF "%_DHCP%"=="No" Then
@echo off
set dnsserver=192.168.25.200
set dnsserver2=192.168.25.201
for /f "tokens=1,2,3*" %%i in ('netsh interface show interface') do (
if %%i EQU Enabled (
rem echo change "%%l" : %dnsserver%
netsh interface ipv4 set dnsserver name="%%l" static %dnsserver% both
netsh interface ipv4 add dnsserver name="%%l" %dnsserver2% index=2
)
)
如果我能弄清楚如何在获取 dhcp 状态的同时提取 IP 地址,我认为它会满足我的需求。
谢谢您的帮助。
解决方案
推荐阅读
- vue.js - 如何在 vuex 动作中制作循环,axios 循环
- google-cloud-dataflow - Apache Beam 中的窗口化和水印:Google 数据流
- python - Python中数据集的URL
- .net - 从 LINQ 到 SQL Query Core 3.1 的“无法将 ..SQLExpression.SQLParameterExpression”转换为 SQLExpression.SQLConstantExpression
- regex - 用于 bigquery 的正则表达式在 /api 之后返回所有路径
- tensorflow - Keras 词嵌入的 tfidf 加权平均值
- google-sheets - 查询 google sheet =>“null”在这个公式中是如何工作的?
- c# - 没有“溢出”的阴影
- facebook - 有什么方法可以通过 api 更新 Facebook 帐户的付款方式?
- android - 在 Android 应用中捕捉 Google 助理的回复