powershell - 在2个选项之间更改dns的批处理文件

标签 powershell batch-file dns

我正在尝试制作Windows 10批处理文件,以从2个选项交换我的dns。第一个是8.8.8.8(google dns),第二个是自定义DNS,允许我观看美国netflix(例如90.90.90.90)。

bash更改dns的命令是

netsh interface ipv4 add dnsserver "Ethernet" address=8.8.8.8 index=1

检查哪个dns已启动并正在运行的命令是:
nslookup 

现在我想做一个IF THEN ELSE,它的工作方式是这样的:
if (dns == 8.8.8.8) 

then (change them to 90.90.90.90)

else (change them to 8.8.8.8)

即使是Powershell脚本也很好

最佳答案

这应该工作:

@echo off

set "dns=8.8.8.8"
for /F "skip=1 tokens=2" %%a in ('nslookup^<NUL') do if "%%a" equ "8.8.8.8" set "dns=90.90.90.90"
netsh interface ipv4 add dnsserver "Ethernet" address=%dns% index=1

关于powershell - 在2个选项之间更改dns的批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33583246/

相关文章:

http - CMD/Batch - cURL HTTP 响应代码的 IF 条件

amazon-web-services - 为在 AWS Route 53 上注册的 Netlify 子域配置 HTTPS

dns - 如何找到域名的权威名称服务器?

mongodb - 如何连接 MongoDB 和 PowerShell?

powershell - 在 powershell 中构建异步脚本

Windows 批处理文件 : PID of last process?

batch-file - 如何关闭不可见的VBS文件

url - 浏览器支持 Unicode URL

python - 如何通过 PowerShell 读取 python 中的文本文件? window 10

powershell - 相当于PowerShell中的历史扩展?