MAC地址与IP绑定_辅助脚本.vbs

'-------------------------------------------------------
'公司有一二十台电脑,今天要做个MAC绑定,免得有人蹭网。
'说多不多,说少不说。写有脚本,辅助一下。
'MAX和IP的对应关系写在脚本当前目标的 ip_list.txt 中,一行一个MAC,IP。
'MAC和IP用逗号分隔。
'2013-12-30 by笨笨 广州乐天
'-------------------------------------------------------

Dim mc,mo,mac,sourceIP,ProcessList,currentPath
currentPath = createobject("Scripting.FileSystemObject").GetFolder(".").Path & "\ip_list.txt"
'MsgBox currentPath
'Wscript.Quit
'---------------------------- --------------------------
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TruE") 
'--------------读取TXT,存入数组-------------------
sub Get_list(FilePath) 
On Error Resume Next 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(FilePath , 1)

	Do Until objTextFile.AtEndOfStream
		strNextLine = objTextFile.Readline
		mylist = mylist & strNextLine & ","
	Loop
	ProcessList = Split(mylist, ",")
end sub 

'-------------------查出 MAC 地址----------------------
set mc=getobject("winmgmts:").instancesof("win32_networkadapterconfiguration")
for each mo in mc
	if mo.ipenabled=true Then
		mac = mo.macaddress		
		exit for
	end if
Next
'-------------------查出 IP 地址----------------------
For Each IPConfig in colNetAdapters  
       If Not IsNull(IPConfig.IPAddress) Then   
           For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)  
               sourceIP = IPConfig.IPAddress(i)
               If sourceIP <> "" Then
               	Exit For	
               End If                  
       Next  
       End If  
Next 
'-------------------从 ip_list.txt 找到对应的IP-----------------------
Get_list(currentPath)
For i = 0 To UBound(ProcessList)
    If ProcessList(i) = mac Then
    	targetIP = ProcessList(i+1)
        Exit For
    end if
Next
'-------------------设置IP 和 DNS----------------------
strIPAddress = Array(targetIP) 
strSubnetMask = Array("255.255.255.0") 
strGateway = Array("192.168.1.1") 
strGatewayMetric = Array(1) 
For Each objNetAdapter in colNetAdapters 
    'IP SubnetMask 子网掩码
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) 
    'Gateway 网关
    'errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) 
    'DNS Server 域名服务器
    'arrDNSServers = Array("8.8.8.8")
    'objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)

    If errEnable = 0 Then 
        MsgBox "本机MAC地址: " & mac & chr(13) & "本机原来IP地址: " & sourceIP & chr(13) & "本机现在IP地址: " & targetIP ,0,"MAC地址与IP绑定,辅助脚本!"
    Else 
        MsgBox "修改IP操作,失败-_-|||." ,0,"MAC地址与IP绑定,辅助脚本!"
    End If 
Next
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

笑虾

多情黯叹痴情癫。情癫苦笑多情难

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值