#根据连接状态查找使用中网卡
gwmi win32_networkadapter -filter "NetConnectionStatus = 2"
#根据是否配置网关查找使用中网卡
$index = (gwmi Win32_NetworkAdapterConfiguration |?{ $_.DefaultIPGateway -ne $null}).Index
$ConnectionID = (gwmi win32_networkadapter -filter "index = $index").NetConnectionID
$ConnectionID

#查找loopback网卡
$index_lb = (gwmi Win32_NetworkAdapterConfiguration | ? {$_.Description -eq "Microsoft Loopback Adapter"}).index

######################################################################

#禁用/启用网卡

netsh.exe interface set interface "$ConnectionID" disabled
netsh.exe interface set interface "$ConnectionID" enabled

设置静态IP及DNS:

netsh interface ip set address "Wi-Fi" source=static addr=192.168.1.234 mask=255.255.255.0 gateway=192.168.1.2
netsh interface ip set dnsservers "Wi-Fi" static 8.8.8.8 primary validate=no    设置第一个DNS地址

添加多个DNS:

netsh interface ip add dnsservers "Wi-Fi" 202.106.0.20 index=2 validate=no   添加第二个DNS地址(注:如果index=1,则变为第一个DNS地址,原第一个下移)

netsh interface ip add dnsservers "Wi-Fi" 202.106.0.21 index=3 validate=no    添加第三个DNS地址

设置动态IP:

netsh interface ip set address "Wi-Fi" source=dhcp
netsh interface ip set dnsservers "Wi-Fi" source=dhcp

Windows Server 2003:

netsh interface ip set dns "本地连接 4" static 100.40.2.53 primary
netsh interface ip add dns "本地连接 4" 100.40.2.54 index=2
netsh interface ip add dns "本地连接 4" 219.232.48.61 index=5
netsh interface ip add dns "本地连接 4" 202.106.196.115 index=6
ipconfig /all

IP及DNS设置(Netsh)的更多相关文章

  1. centos6.5静态IP和DNS设置

    sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0EVICE=eth0HWADDR=60:02:92:62:30:2ATYPE=EthernetBROA ...

  2. 批处理文件设置IP以及DNS

    先附上批处理文件代码(批处理文件怎么创建自己另行百度,这里不再赘述) Echo offecho ==============请输入序号修改办公区===========echo *********1.家 ...

  3. 利用netsh命令设置IP地址/DNS服务器地址

    一.设置IP地址 1. 自动获取IP地址: netsh interface ip set address [name=]"本地连接" [source=]dhcp 2. 手动设置IP ...

  4. .bat文件设置IP、DNS

    这几天遇到个烦心事,每次开机之后都要去手动去设置一下IP地址,一大串的数字还是有点麻烦,于是就想写个批处理文件设置IP 注意:在DOS下设置IP时需要管理员权限运行 1.查看机子设置IP需要用到的名字 ...

  5. 本地IP,掩码,网关,DNS设置

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. windows命令行设置IP与DNS

    用dos命令修改IP等本地连接属性 平时我们改IP通常都在是窗口界面本地连接直接修改, 那在命令行也可以设置IP地址?当然可以,这里要用到netsh命令 .点击“开始”->“运行”,输入“cmd ...

  7. 设置自动获取IP和DNS

    问题阐述 设置ipv4的自动获取时遇到一个问题,ip和dns自动获取可以确认设置,但是全局时就是报错,回头去看ipv4的ip和dns也还是原来的样子 由于一直使用的都是自动获取,很少会有主动设置ip或 ...

  8. Centos6.2设置静态ip和dns

    参考了如下文章:https://gist.github.com/fernandoaleman/2172388http://www.lifelinux.com/how-to-configure-stat ...

  9. Centos 7 安装 设置 IP地址,DNS,主机名,防火墙,端口,SELinux (实测+笔记)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.虚拟系统安装 1.1 使 ...

随机推荐

  1. 【OpenCV-Python】-几何变换

    涉及函数: cv2.getPerspectiveTransform()cv2.warpAffine() 接收的参数是2✖️3的变换矩阵cv2.warpPerspective() 接收的参数是3✖️3的 ...

  2. 使用maven构建多模块项目_记录

    参照孤傲苍狼的博客:https://www.cnblogs.com/xdp-gacl/p/4242221.html 备注:博客中的生成语句,适用于maven3.0.5以上,若为3.0.5以下,则将cr ...

  3. Centos7修改主机名称、DNS、网卡信息

    1 hostnamectl set-hostname wangshuyi 2 vi /etc/hostname 3 vi /etc/resolv.conf 4 vi /etc/sysconfig/ne ...

  4. mysql并发更新问题

    问题背景: 假设MySQL数据库有一张会员表vip_member(InnoDB表),结构如下:   当一个会员想续买会员(只能续买1个月.3个月或6个月)时,必须满足以下业务要求: •如果end_at ...

  5. selenium+Python(事件)

    1.操作测试对象前面讲到了不少知识都是定位元素,定位只是第一步,定位之后需要对这个元素进行操作.鼠标点击或者键盘输入,这要取决于我们定位的是按钮还输入框.一般来说,webdriver 中比较常用的操作 ...

  6. Node.js静态文件服务器

    首先还是先感谢github,感谢github上提供此段源码的作者.跟昨晚看的静态文件服务器来比今天的静态文件服务器稍微复杂些,可以学到很多新的东西.仔细会发现这次的代码多了一个fs.stat函数和Re ...

  7. poj 3748 位操作

    位操作 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8856   Accepted: 3535 Description 假 ...

  8. xcode配置文件中,Architectures表示的意义

    xcode配置文件中,Architectures表示的意义 ======================== Architecture : 指你想支持的指令集. Valid architectures ...

  9. Go在windows10 64位上安装

    一.安装 1.下载安装包http://www.golangtc.com/download,这是国内的地址,也直接去官网下载. 2.选择适合自己的版本,这里我选择安64位装版go1.9.2.window ...

  10. [转]weui-wxss WeUI for 小程序 为微信小程序量身设计

    本文转自:https://github.com/weui/weui-wxss/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=tou ...