Corey Scheich
asked on
Get remote IP or MAC
I am trying to get the IP address or MAC id of a computer on the same lan. I would like to use .NET calls to do this. I found the following but it seems to require Admin rights to the computer. Is there any way to do this without using windows API calls or a High Level Login. I would be alright with the ability to do it with a restricted domain user login though
I found the code here
https://www.experts-exchange.com/questions/21469047/retreive-MAC-address-off-remote-machine.html
Public Shared Function GetMAC(ByVal ComputerName As String)
Dim MAC As String = ""
Try
Dim query As String = "SELECT * FROM Win32_NetworkAdapterConfig uration"
Dim searchAddresses As New ManagementObjectSearcher(q uery)
Dim ConOpts As New ConnectionOptions()
ConOpts.Password = "Pswd"
ConOpts.Username = "Domain\LoginName"
Dim SearchScope As ManagementScope = New ManagementScope("\\" & ComputerName & "\root\cimv2", ConOpts)
searchAddresses.Scope = SearchScope
Dim objColl As ManagementObjectCollection
objColl = searchAddresses.Get()
Debug.Print(objColl.ToStri ng)
For Each Adapter As ManagementObject In objColl
If Adapter("MacAddress") IsNot Nothing Then
MAC = Adapter("MacAddress") '(0)
End If
Next
Catch ex As Exception
Debug.Print(ex.Message & vbCrLf & vbCrLf & ex.StackTrace)
End Try
Return IP
End Function
I found the code here
https://www.experts-exchange.com/questions/21469047/retreive-MAC-address-off-remote-machine.html
Public Shared Function GetMAC(ByVal ComputerName As String)
Dim MAC As String = ""
Try
Dim query As String = "SELECT * FROM Win32_NetworkAdapterConfig
Dim searchAddresses As New ManagementObjectSearcher(q
Dim ConOpts As New ConnectionOptions()
ConOpts.Password = "Pswd"
ConOpts.Username = "Domain\LoginName"
Dim SearchScope As ManagementScope = New ManagementScope("\\" & ComputerName & "\root\cimv2", ConOpts)
searchAddresses.Scope = SearchScope
Dim objColl As ManagementObjectCollection
objColl = searchAddresses.Get()
Debug.Print(objColl.ToStri
For Each Adapter As ManagementObject In objColl
If Adapter("MacAddress") IsNot Nothing Then
MAC = Adapter("MacAddress") '(0)
End If
Next
Catch ex As Exception
Debug.Print(ex.Message & vbCrLf & vbCrLf & ex.StackTrace)
End Try
Return IP
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.