使用脚本自动修改ip设置

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了使用脚本自动修改ip设置脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
vbs脚本的功能非常强大, 理系简单方便!下面的脚本win2000和winxp都可以使用,win2003没有测试过, 应该也没有问题。如果需要经常切换网关,或是ip,这个脚本是最方便的了。稍微修改一下甚至可以做到1分钟变一次ip。

复制代码 代码如下:

@Echo Off
TITLE  脚本宝典ip设置器

:start
CLS
COLOR 2f
:: 使用COLOR命令对控制台输出颜色进行更改
mode con cols=56 lines=20
:: MODE语句为设定窗体的和高
:sc_main
echo       -------------------------------------------
echo.&echo.
echo             0.192.168.0.99 & echo.
echo             1.192.168.1.99 & echo.
echo             q.退出 & echo.&echo.&echo.&echo.&echo.&echo.

set "select="
set/p select= 输入数字,按回车继续 :
if "%select%"=="0" (goto sc_ip0)
if "%select%"=="1" (goto sc_ip1)
if "%select%"=="Q" (goto sc_exit)

:sc_exit
exit
goto :eof

:sc_ip0
cls
echo 正在设置中,请稍候
Netsh interface IP Set Address "本地连接" static 192.168.0.99 255.255.255.0 192.168.0.1 1
Netsh interface IP set dns "本地连接" static 192.168.0.1 Primary
echo 设置成功 192.168.0.99
PAUSE >nul
Goto sc_main
:sc_ip1
cls
echo 正在设置中,请稍候
Netsh interface IP Set Address "本地连接" Static 192.168.1.99 255.255.255.0 192.168.1.1 1
Netsh interface IP set dns "本地连接" static 192.168.1.1 PRimary
echo 设置成功 192.168.1.99
PAUSE >nul
Goto sc_main

vbs修改ip

复制代码 代码如下:

changeip.vbsstrComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterconfiguration where IPEnabled=TRUE")


For each objNetAdapter in colNetAdapters
sip=objNetAdapter.IPAddress
strIPAddress = sip      '保持原来的ip,如果需要修改ip为192.168.0.200:strIPAddress = Array("192.168.0.200")
strSubnetmask = Array("255.255.255.0")
strGateway = Array("192.168.0.254")     '修改网关为192.168.0.254
strGatewayMetric = Array(1)

    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    If errEnable = 0 Then
        WScript.Echo "The IP address has been changed."
    Else
        WScript.Echo "The IP address could not be changed."
    End If
    exit for      '只修改第一个网卡的设置
Next

VBS修改IP

复制代码 代码如下:

'VBS修改IP
function transh(s)
if isnumeric(s) then
if len(s)=1 then
   transh="00" & s
elseif len(s)=2 then
   transh="0" & s
elseif len(s)=3 then
   transh=s
end if
else
   transh=""
end if
end function
dim head
'机器名头
head="B"
'ip头
iphead="192.168.131"
ipgate="192.168.131"

dim i
i=inputbox("输入机器序号(2-254)")
if i="" then
msgbox "Error: 序号不正确!"
else
dim shell
set shell = CreateObject("WScript.Shell")

'修改计算机名
shell.RegWrite "HKLM\SysTEM\currentControlSet\Control\ComputerName\ComputerName\ComputerName", head & transh(i) ,"REG_SZ"
shell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname", head & transh(i) ,"REG_SZ"
shell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname", head & transh(i) ,"REG_SZ"
'修改IP
shell.run "netsh interface ip set address 本地连接 static " & iphead & "." & i & " 255.255.255.0 " & ipgate & ".252 1"
'msgbox "OK"
        shell.run "netsh interface ip set address 本地连接 static " & iphead & "." & i & " 255.255.255.0 " & ipgate & ".252 1"
'msgbox "OK"
        shell.run "netsh interface ip set address 本地连接 static " & iphead & "." & i & " 255.255.255.0 " & ipgate & ".252 1"
'msgbox "OK"
end if

脚本宝典总结

以上是脚本宝典为你收集整理的使用脚本自动修改ip设置全部内容,希望文章能够帮你解决使用脚本自动修改ip设置所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: