注意:這個方法是 .NET Framework 2.0 版的新功能。

以這台電腦為例,其網路資訊如下:

100222--2.jpg

程式範例:

'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

 

取得本機電腦之網路連接的相關資訊。

100222--4.jpg

程式範例:

 

'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

100222--3.jpg

程式範例:

'取得本機系統正在 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 類別

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 tsuozoe 的頭像
    tsuozoe

    隨便寫寫的新天地

    tsuozoe 發表在 痞客邦 留言(0) 人氣()