Можно ли изменить МАС адрес средствами vbs
Хочу спросить можно ли изменить МАС адрес сетевой карты посредством vbs?
Если да то как?
И ищо. Можно ли получит МАС удаленной машины имея IP этой машины?
Я понимаю что есть куча прог которые это делают. Просто я хочу знать может ли это осуществить VBScript.
Если глупый вопрос не обижайтесь я новичок ))
|
1. можно через реестр, но потребуется перезагрузка:
Код:
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strMACAddr = "001E0B3D3F0B"
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
Set colNetCards = objWMIService.ExecQuery( _
"Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
strSettingID = objNetCard.SettingID
If Len(strSettingID)=38 Then Exit For
Next
objReg.EnumKey HKEY_LOCAL_MACHINE,strKeyPath,arrSubKeys
For Each SubKey In arrSubKeys
objReg.GetStringValue HKEY_LOCAL_MACHINE, _
strKeyPath & "\" & SubKey, "NetCfgInstanceId", strValue
If Not(IsNull(strValue)) And strValue = strSettingID Then
objReg.SetStringValue HKEY_LOCAL_MACHINE, _
strKeyPath & "\" & SubKey, "NetworkAddress", strNewMACAddr
Exit For
End If
Next
2. аналогично (вместо точки подставить имя компьютера):
Код:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery( _
"Select IPAddress From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
strIPAddress = objNetCard.IPAddress(0)
Next
WScript.Echo strIPAddress
|
За первое спасибо.
Но второе ты наверное не так понял.
Я сказал «Можно ли узнать МАС адрес удаленной машины имея ёё IP»
|
Аналогичнейшим же вышеприведённому скрипту amel27 [он, скорее всего, просто промахнулся в определении]:
Код:
strDestIPAdress = "192.168.0.1"
Set objWMIService = GetObject("winmgmts:\\" & strDestIPAdress & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery( _
"Select Caption, IPAddress, MACAddress From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
For Each elem In objNetCard.IPAddress
If elem = strDestIPAdress Then
WScript.Echo objNetCard.Caption, objNetCard.MACAddress
End If
Next
Next
|
Вот ещё один вариант, с использованием сторонней библиотеки:
Код:
Option Explicit
Const sscNBSTATSuccess = 0
Dim objNBTNetwork
Dim strMACAddress
Dim strDestAddress
strDestAddress = "192.168.223.3"
' «SScripting.NBTNetwork» из библиотеки «System Scripting Runtime» (http://www.netal.com/ssr.htm)
Set objNBTNetwork = WScript.CreateObject("SScripting.NBTNetwork")
If objNBTNetwork.QueryNodeStatus(strDestAddress, 1000, strMACAddress) = sscNBSTATSuccess Then
WScript.Echo strMACAddress
Else
WScript.Echo "Can't connect to [" & strDestAddress & "]."
End If
WScript.Quit 0
|
Всем спасибо. Тема закрыта.
|
Время: 01:26.
© OSzone.net 2001-