注意:這個方法是 .NET Framework 2.0 版的新功能。
以這台電腦為例,其網路資訊如下:
程式範例:
'Windows IP Configuration Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
MessageBox.Show("Host Name .......................... : " + computerProperties.HostName + vbCrLf + _ "Primary Dns Suffix .......................... : " + computerProperties.DomainName)
'Ethernet adapter Dim nics As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces() Dim adapter As Net.NetworkInformation.NetworkInterface
For Each adapter In nics Dim properties As IPInterfaceProperties = adapter.GetIPProperties()
MessageBox.Show(adapter.Description.ToString + vbCrLf + _ String.Empty.PadLeft(adapter.Description.Length, "="c) + vbCrLf + _ " Interface type .......................... : " + adapter.NetworkInterfaceType + vbCrLf + _ " Physical Address ........................ : " + adapter.GetPhysicalAddress().ToString() + vbCrLf + _ " Is receive only.......................... : " + adapter.IsReceiveOnly.ToString + vbCrLf + _ " Multicast................................ : " + adapter.SupportsMulticast.ToString) Next adapter
|
取得本機電腦之網路連接的相關資訊。
程式範例:
'Show Inbound IPStatistics Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties() Dim ipstat4 As IPGlobalStatistics = computerProperties.GetIPv4GlobalStatistics
MessageBox.Show("Inbound Packet Data:" + vbCrLf + _ " Received ............................ : " + ipstat4.ReceivedPackets.ToString + vbCrLf + _ " Forwarded ........................... : " + ipstat4.ReceivedPacketsForwarded.ToString + vbCrLf + _ " Delivered ........................... : " + ipstat4.ReceivedPacketsDelivered.ToString + vbCrLf + _ " Discarded ........................... : " + ipstat4.ReceivedPacketsDiscarded.ToString)
|
取得本機系統正在 Listening 的 port
程式範例:
'取得本機系統正在 Listening 的 port Dim computerProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties() Dim IPEndPoint() As EndPoint = computerProperties.GetActiveTcpListeners() Dim myIPEndPoint As IPEndPoint Dim strResult As String = ""
For Each myIPEndPoint In IPEndPoint
strResult += "Listening Address=" + myIPEndPoint.Address.ToString + ",Port=" + myIPEndPoint.Port.ToString + vbCrLf
Next
MessageBox.Show(strResult)
|
請參考:
[MSDN] NetworkInterface.GetPhysicalAddress 方法
[MSDN] IPGlobalProperties 類別
留言列表