脚本专栏 
首页 > 脚本专栏 > 浏览文章

使用脚本自动修改ip设置

(编辑:jimmy 日期: 2024/5/9 浏览:3 次 )
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

上一篇:切换dos并dir的vbs
下一篇:VBScript 中的字节数据操作函数
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网