手机
当前位置:查字典教程网 >脚本专栏 >vbs >使用脚本自动修改ip设置
使用脚本自动修改ip设置
摘要:vbs脚本的功能非常强大,管理系统简单方便!下面的脚本win2000和winxp都可以使用,win2003没有测试过,应该也没有问题。如果需...

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 & "rootcimv2")

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 "HKLMSYSTEMCurrentControlSetControlComputerNameComputerNameComputerName", head & transh(i) ,"REG_SZ"

shell.RegWrite "HKLMSYSTEMCurrentControlSetServicesTcpipParametersNV Hostname", head & transh(i) ,"REG_SZ"

shell.RegWrite "HKLMSYSTEMCurrentControlSetServicesTcpipParametersHostname", 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设置】相关文章:

使用VBS修改二进制文件HEX数据

使用 Iisftp.vbs 设置Active Directory 用户隔离

用vbs确定脚本正在哪一个帐户下运行

使用VBS获取当前日期的前一天 并修正输出格式

一次载入2个vbs脚本的方法

Windows管理脚本学习

使用脚本调用系统的关机对话框实现代码

禁止QQ上网的vbs脚本代码

用VBS修改(设置)系统时间和日期的代码

使用VBS访问外部文本文件一些方法和脚本实例代码

精品推荐
分类导航