Link to home
Start Free TrialLog in
Avatar of Hepen
Hepen

asked on

Can someone clean up this function for me?

This function seems inefficient.

I want it to just return the clients(user) mac address with as little code as possible.

Imports System.Management

Private Function GetMacAddress() As String

        Dim mc As System.Management.ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
        Dim moc As ManagementObjectCollection = mc.GetInstances()
        Dim mo As ManagementObject

        Dim strMacAddress As String = "N/A"
        For Each mo In moc
            If mo.Item("IPEnabled") Then
                strMacAddress = mo.Item("MacAddress").ToString()
            End If
        Next

        If IsNothing(strMacAddress) Then
            Return "n/a"
        Else
            Return strMacAddress
        End If

    End Function
ASKER CERTIFIED SOLUTION
Avatar of ZeonFlash
ZeonFlash

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial