zoukankan      html  css  js  c++  java
  • 用vbs自动切换不同网段的IP

    开发和测试环境处于不同的网段,经常需要更改IP,手工修改非常麻烦。后来找到了一个vbs小脚本,实现了自动切换。

    假如IP段分别为192.168.30.*和192.168.41.*

    分别新添两个文件Turn30.vbs和Turn41.vbs ,内容如下:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery _
        (
    "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
    strIPAddress 
    = Array("192.168.30.99")
    strSubnetMask 
    = Array("255.255.255.0")
    strGateway 
    = Array("192.168.30.254")
    strDNS = Array("192.168.30.254")
    strGatewayMetric = Array(1)
    strDNS2 = Array(1)
    For Each objNetAdapter in colNetAdapters
        errEnable 
    = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
        errGateways 
    = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
        errDNS=objNetAdapter.SetDNSServerSearchOrder(strDNS,strDNS2)
        If errEnable = 0 Then
            WScript.Echo 
    "The IP address has been changed to "&strIPAddress(0)
        
    Else
            WScript.Echo 
    "The IP address could not be changed."
        
    End If
    Next 

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNetAdapters = objWMIService.ExecQuery _
        (
    "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
    strIPAddress 
    = Array("192.168.41.52")
    strSubnetMask 
    = Array("255.255.255.0")
    strGateway 
    = Array("192.168.41.1")
    strDNS = Array("192.168.41.254")
    strGatewayMetric = Array(1)
    strDNS2 = Array(1)
    For Each objNetAdapter in colNetAdapters
        errEnable 
    = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
        errGateways 
    = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
         errDNS=objNetAdapter.SetDNSServerSearchOrder(strDNS,strDNS2)
        If errEnable = 0 Then
            WScript.Echo 
    "The IP address has been changed to "&strIPAddress(0)
        
    Else
            WScript.Echo 
    "The IP address could not be changed."
        
    End If
    Next

    使用方法:直接双击Turn30.vbs或Turn41.vbs即可执行。

    参考网站:
    http://www.microsoft.com/china/technet/community/scriptcenter/network/scrnet01.mspx

    邀月注:本文版权由邀月和博客园共同所有,转载请注明出处。
    助人等于自助!  3w@live.cn
  • 相关阅读:
    MySQL无法登录服务器解决方法
    photoshop mac版下载及破解
    静态html传参数
    flash与php 交互(as传参给php)
    PHP发送邮件类库PHPMailer的简单使用
    PHP CodeBase: 判断用户是否手机访问
    HTTP报文
    有关phpmailer的详细介绍及使用方法
    JS 实现 Tab标签切换功能
    new Option()——实现时间联动
  • 原文地址:https://www.cnblogs.com/downmoon/p/1629664.html
Copyright © 2011-2022 走看看