Get active mac-address

S

Stefan

hi,
i use this function to get the all mac adresses
how can i modify this function to get only the active connection.
Public Function GetMacAddress() As String

Dim mc As System.Management.ManagementClass

Dim mo As ManagementObject

mc = New ManagementClass("Win32_NetworkAdapterConfiguration")

Dim moc As ManagementObjectCollection = mc.GetInstances()

For Each mo In moc

If CBool(mo.Item("IPEnabled")) = True Then

MessageBox.Show("MAC address " & mo.Item("MacAddress").ToString())

End If

Next

End Function
 
K

Ken Tucker [MVP]

Hi

Try this.

' Add a Reference to System.Management
Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject
moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_NetworkAdapter Where AdapterTypeID = 0")
moReturn = moSearch.Get
For Each mo In moReturn
Dim strOut As String
strOut = String.Format("Name {0} - Address {1}", mo("Name"),
mo("MacAddress"))
Trace.WriteLine(strOut)
Next

Ken
----------------------------------
hi,
i use this function to get the all mac adresses
how can i modify this function to get only the active connection.
Public Function GetMacAddress() As String
Dim mc As System.Management.ManagementClass
Dim mo As ManagementObject
mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
For Each mo In moc
If CBool(mo.Item("IPEnabled")) = True Then
MessageBox.Show("MAC address " & mo.Item("MacAddress").ToString())
End If
Next
End Function
 
S

Stefan

Ken,
appreciate your help but
all the adapters are returned
not just the active one (active one: the one i use to get on the network)

kind regards,

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top