前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >根据mac来配置ip的vbs脚本

根据mac来配置ip的vbs脚本

作者头像
力哥聊运维与云计算
发布2019-06-28 11:32:32
1.1K0
发布2019-06-28 11:32:32
举报

 vbs 脚本 setnicip.vbs 内容如下:

'Option Explicit

Const ForReading= 1,ForWriting = 2,ForAppending = 8

Dim fso,file,msg

Dim   WshShell,Path_init_file

Dim   routmac,routip,routmask,routgw

Dim   rinmac,rinip,rinmask,ringw

Dim   k,m

Set   WshShell=WScript.CreateObject( "WScript.Shell")   

Path_init_file=left(Wscript.ScriptFullName,len(Wscript.ScriptFullName)-len(Wscript.ScriptName))& "nicinfo.ini" 

'msgbox(path_init_file)

Set fso=CreateObject("Scripting.FileSystemObject")

Set file=fso.OpenTextFile(Path_init_file,ForReading)

While (Not file.AtEndOfLine)

  msg=file.ReadLine

  msg=trim(msg)

  if instr(msg,"outmac:")>0 then

       k = InStr(msg, ":")

       m = Len(msg)

       routmac = Right(msg, m - k)

       'msgbox(routmac)

  else

  end if

  if instr(msg,"outip:")>0 then

       k = InStr(msg, ":")

       m = Len(msg)

       routip = Right(msg, m - k)

       'msgbox(routip)

  else

  end if

  if instr(msg,"outmask:")>0 then

       k = InStr(msg, ":")

       m = Len(msg)

       routmask = Right(msg, m - k)

       'msgbox(routmask)

  else

  end if

  if instr(msg,"outgw:")>0 then

       k = InStr(msg, ":")

       m = Len(msg)

       routgw = Right(msg, m - k)

       'msgbox(routgw)

  else

  end if

'+++++++++++++++++++++++++++++++++++++++++++++

  if instr(msg,"inmac:")>0 then

       k = InStr(msg, ":")

       m = Len(msg)

       rinmac = Right(msg, m - k)

       'msgbox(rinmac)

  else

  end if

  if instr(msg,"inip:")>0 then

       k = InStr(msg, ":")

       m = Len(msg)

       rinip = Right(msg, m - k)

       'msgbox(rinip)

  else

  end if

  if instr(msg,"inmask:")>0 then

       k = InStr(msg, ":")

       m = Len(msg)

       rinmask = Right(msg, m - k)

       'msgbox(rinmask)

  else

  end if

  if instr(msg,"ingw:")>0 then

       k = InStr(msg, ":")

       m = Len(msg)

       ringw = Right(msg, m - k)

          if ringw="none" then 

          ringw=""

          else

          end if

       'msgbox(ringw)

  else

  end if

Wend

file.Close

Set file=Nothing

Set fso=Nothing

'Dim strComputer,objWMIService,colNetAdapters,strIPAddress,strSubnetMask,strGateway,errEnable,errGateways,objNetAdapter 

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where (MACAddress ='"+ routmac+"' )")

strIPAddress = Array(routip)

strSubnetMask = Array(routmask)

strGateway = Array(routgw)

strGatewaymetric = Array(1)

For Each objNetAdapter In colNetAdapters

     errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

     errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

next

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=

Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where (MACAddress = '"+rinmac+"')")

strIPAddress = Array(rinip)

strSubnetMask = Array(rinmask)

strGateway = Array(ringw)

For Each objNetAdapter In colNetAdapters

errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)

errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)

next

在同一个目录下,建立一个文件,名叫nicinfo.ini,内容如下:

outmac:00:15:AF:C8:5D:E3

outip:192.168.56.2

outmask:255.255.255.0

outgw:

inmac:00:AC:D9:00:8A:16

inip:172.16.254.6

inmask:255.255.255.0

ingw:none

根据自己的需要,修改配置文件内容,然后运行vbs脚本,就可以修改ip了。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2011-07-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档