'-------------------------------------------------------
'公司有一二十台电脑,今天要做个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
MAC地址与IP绑定_辅助脚本.vbs
最新推荐文章于 2024-07-20 00:00:00 发布