First, create a class that can hold all the info you want to return:
Public Class NetworkInterfaceInfo
Public Sub New(ByVal ipAddress As IPAddress, ByVal physicalAddress As PhysicalAddress)
_ipAddress = ipAddress
_physicalAddress = physicalAddress
End Sub
Public ReadOnly Property IpAddress() As IPAddress
Get
Return _ipAddress
End Get
End Property
Private _ipAddress As IPAddress
Public ReadOnly Property PhysicalAddress() As PhysicalAddress
Get
Return _physicalAddress
End Get
End Property
Private _physicalAddress As PhysicalAddress
End Class
Then, make a method that loops through all the network interfaces and finds the ones that meet your criteria. Then, loop through all the IP addresses for those interfaces until you find one that meets your criteria. Once you find a match, return the info:
Public Function GetNetworkInterfaceInfo() As NetworkInterfaceInfo
For Each networkInterface As NetworkInterface In networkInterface.GetAllNetworkInterfaces()
If networkInterface.OperationalStatus = OperationalStatus.Up Then
For Each address As IPAddress In networkInterface.GetIPProperties().DnsAddresses()
If address.AddressFamily = AddressFamily.InterNetwork Then
Return New NetworkInterfaceInfo(address, networkInterface.GetPhysicalAddress())
End If
Next
End If
Next
Return Nothing
End Function