如何使用vbs脚本自动修改ip设置

发布时间:2021-09-01 23:40:52 作者:chen
来源:亿速云 阅读:421

本篇内容主要讲解“如何使用vbs脚本自动修改ip设置”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用vbs脚本自动修改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

到此,相信大家对“如何使用vbs脚本自动修改ip设置”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. 自动获取公网ip的脚本
  2. Linux下IP如何设置脚本

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ip vbs

上一篇:DOS的基本概念

下一篇:怎么用ajax技术制作在线歌词搜索功能

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》