欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

CMD和vbs修改 IP地址及DNS的实现代码

程序员文章站 2022-08-27 15:06:19
修改ip cmd /c netsh interface ip set address name=" 本地连接" source=static addr=211.82.56.2...
修改ip

cmd /c netsh interface ip set address name=" 本地连接" source=static addr=211.82.56.253 mask=255.255.255.0 gateway=211.82.56.1 gwmetric=1

修改dns
cmd /c netsh interface ip set dns name="本地连接" source=static addr=202.99.192.66


配置或更新ip地址:
wmic nicconfig where index=0 call enablestatic("192.168.1.5"), ("255.255.255.0") ;index=0说明是配置网络接口1。


配置网关(默认路由):
wmic nicconfig where index=0 call setgateways("192.168.1.1"),(1)


vbs

const t_gateway = "211.82.56.1" '网关
const t_newdns1 = "202.99.192.66" 'dns1
const t_newdns2 = "60.221.248.43" 'dns2
strwinmgmt="winmgmts:{impersonationlevel=impersonate}"
set nics = getobject( strwinmgmt ).instancesof("win32_networkadapterconfiguration")
for each nic in nics
if nic.ipenabled then
nic.setdnsserversearchorder array(t_newdns1,t_newdns2)
nic.setgateways array(t_gateway)
end if
next