For Each nic As System.Net.NetworkInformation.NetworkInterface In System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
If nic.OperationalStatus = Net.NetworkInformation.OperationalStatus.Up Then
MessageBox.Show(String.Format("The MAC address of {0} is{1}{2}", nic.Description, Environment.NewLine, nic.GetPhysicalAddress()))
End If
End For
Imports System
Imports System.Management
Public Class Form1
Inherits System.Windows.Forms.Form
Dim MyManagementClass As New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim MyManagementObjectCollection As ManagementObjectCollection = MyManagementClass.GetInstances()
Dim MyManagementObject As ManagementObject
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each MyManagementObject In MyManagementObjectCollection
If MyManagementObject.Item("IPEnabled") = True Then
'รับค่า IP
Dim IP() As String = MyManagementObject.Item("IPAddress")
MessageBox.Show("IP address " & IP(0) _
& vbCrLf & "MAC address " & MyManagementObject.Item("MacAddress").ToString())
End If
Next
End Sub
End Class