欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用脚本自动修改ip设置

程序员文章站 2022-03-21 15:34:13
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 & "\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