Chinaunix首页 | 论坛 | 博客
  • 博客访问: 529226
  • 博文数量: 90
  • 博客积分: 7000
  • 博客等级: 少将
  • 技术积分: 1110
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-05 11:02
文章分类

全部博文(90)

文章存档

2017年(2)

2011年(1)

2008年(18)

2007年(33)

2006年(36)

我的朋友

分类: WINDOWS

2007-02-24 21:01:00

文件: 切换网关.rar
大小: 0KB
下载: 下载
文件: VBScript.rar
大小: 348KB
下载: 下载
 
存为vbs后缀名,运行.
 
dim GateWay()
dim info(5)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'可选网关1
info(0)="电信"
info(1)="192.168.1.10"  '本机IP
info(2)="255.255.255.0" '子网掩码
info(3)="192.168.1.1" '网关
info(4)="201.96.112.133"  '首选DNS
info(5)="84.124.96.122"  '备用DNS
Redim PreServe GateWay(0)
GateWay(Ubound(GateWay))=info
'可选网关2
info(0)="网通"
info(1)="192.168.1.2"  '本机IP
info(2)="255.255.255.0" '子网掩码
info(3)="192.168.1.1" '网关
info(4)="201.96.112.133"  '首选DNS
info(5)="84.124.96.122"  '备用DNS
Redim PreServe GateWay(Ubound(GateWay)+1)
GateWay(Ubound(GateWay))=info
'如有更多网关,请复制可选网关2,然后修改其中的网关信息
 
For i=0 to ubound(GateWay)
if msgbox("选择“" & GateWay(i)(0) & "”请按是,否则请按否",vbquestion+vbyesno)=vbyes then
msgbox ChangeIP(GateWay(i)(1), GateWay(i)(2), GateWay(i)(3), GateWay(i)(4), GateWay(i)(5))
exit for
end if
Next
Function ChangeIP(IP, NM, GW, MDNS, SDNS)
  Dim strComputer, objWMIService, colNetAdapters, strIPAddress, strSubnetMask
  Dim strGateway, strGatewaymetric, strDNS, objNetAdapter, errEnable, errGateways, errDNS
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
  strIPAddress=Array(IP)
  strSubnetMask=Array(NM)
  strGateway=Array(GW)
  strDNS = Array(MDNS, SDNS)
  strGatewaymetric = Array(1)
  For Each objNetAdapter In colNetAdapters
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNS)
    If errEnable = 0 And errGateways = 0 And errDNS = 0 Then
      ChangeIP = "设置成功"
    Else
      If errEnable = 0 Then
          ChangeIP = "IP地址和子网掩码设置成功, "
      Else
          ChangeIP = "IP地址或子网掩码设置失败, "
      End If
      If errGateways = 0 Then
          ChangeIP = ChangeIP & "默认网关设置成功, "
      Else
          ChangeIP = ChangeIP & "默认网关设置失败, "
      End If
      If errDNS = 0 Then
          ChangeIP = ChangeIP & "DNS设置成功"
      Else
          ChangeIP = ChangeIP & "DNS设置失败"
      End If
    End If
  Next
  End Function
阅读(2846) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~