CMD和vbs修改 IP地址及DNS的實現(xiàn)代碼
更新時間:2009年01月05日 12:14:23 作者:
命令行下對IP地址及DNS的操作 包括netsh和wmic兩個版本 和vbs下對網(wǎng)關(guān)和DNS的修改
修改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說明是配置網(wǎng)絡(luò)接口1。
配置網(wǎng)關(guān)(默認路由):
wmic nicconfig where index=0 call setgateways("192.168.1.1"),(1)
vbs
Const T_GATEWAY = "211.82.56.1" '網(wǎng)關(guān)
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
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說明是配置網(wǎng)絡(luò)接口1。
配置網(wǎng)關(guān)(默認路由):
wmic nicconfig where index=0 call setgateways("192.168.1.1"),(1)
vbs
Const T_GATEWAY = "211.82.56.1" '網(wǎng)關(guān)
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
相關(guān)文章
WMI 創(chuàng)建系統(tǒng)服務(wù)的實現(xiàn)代碼(Automatic)
需要注意的是啟動模式,應(yīng)為“Automatic”,而不是“Auto”2013-07-07vbs實現(xiàn)恢復(fù)暫停的自動啟動服務(wù)的腳本
有時候我們需要把自啟動的服務(wù)停掉,方便我們處理事務(wù),但我們?nèi)绻淮瓮5舻淖詥臃?wù)比較多,如何一次性啟動他們呢2008-06-06VBS獲取GZIP壓縮的HTTP內(nèi)容的實現(xiàn)代碼
這篇文章主要介紹了VBS獲取GZIP壓縮的HTTP內(nèi)容的實現(xiàn)代碼,需要的朋友可以參考下2016-01-01WScript.Shell對象SpecialFolders屬性未公開文檔分享
WshShell對象的SpecialFolders屬性返WshSpecialFolders 對象,該對象是一個特殊文件夾集合,其中包含整套Windows特殊文件夾2013-01-01使用xcacls.vbs(cacls.exe)修改NTFS權(quán)限說明(中文版)
本分步指南介紹如何使用擴展的更改訪問控制列表工具 (cacls.exe,對應(yīng)的腳本文件是xcacls.vbs) 修改和查看文件或文件夾的 NTFS 權(quán)限。2010-08-08