您好,登錄后才能下訂單哦!
這篇文章給大家介紹VB.NET中怎么實現網絡監控,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
1.在窗體上放置一個TreeView控件,改名為tvInfo。
2.再放置一個按鈕控件。
3.雙擊按鈕,編寫VB.NET網絡監控代碼。
Dim _ManagementObjectSearcher As
New System.Management.Management
ObjectSearcher("SELECT * FROM
Win32_NetworkAdapterConfiguration")
Dim _ParenNode As TreeNode =
Nothing '父節點
Me.tvInfo.Nodes.Clear()
Try
For Each ManObj As System.
Management.ManagementObject
In _ManagementObjectSearcher.Get
_ParenNode = New TreeNode
(ManObj("Description"))
If CBool(ManObj("IPEnabled")) Then
創建 ip地址及子網掩碼 子節點
Dim _IpNode As New TreeNode
("IP Address | Default Gateway")If (ManObj("IPAddress")
IsNot Nothing) ThenFor i As Integer = 0 To
UBound(ManObj("IPAddress"))_IpNode.Nodes.Add(New TreeNode
(ManObj("IPAddress")(i) & "
| " & ManObj("IPSubnet")(i)))Next
Else
_IpNode.Nodes.Add(New
TreeNode("Null"))End If
創建 默認網關 子節點
Dim _GatewayNode As New
TreeNode("Default Gateway")If (ManObj("DefaultIPGateway")
IsNot Nothing) ThenFor i As Integer = 0 To UBound
(ManObj("DefaultIPGateway"))_GatewayNode.Nodes.Add(New
TreeNode(ManObj("DefaultIP
Gateway")(i)))Next
Else
_GatewayNode.Nodes.Add(New
TreeNode("Null"))End If
Dim _DNSNode As New TreeNode
("DNS Servers")If (ManObj("DNSServerSearchOrder")
IsNot Nothing) ThenFor i As Integer = 0 To UBound
(ManObj("DNSServerSearchOrder"))_DNSNode.Nodes.Add(New TreeNode
(ManObj("DNSServerSearchOrder")(i)))Next
Else
_DNSNode.Nodes.Add(New TreeNode("Null"))
End If
_ParenNode.Nodes.AddRange( _
New TreeNode() { _
New TreeNode(String.Format
("Physical Address:{0}", ManObj
("MACAddress"))), _New TreeNode(String.Format
("DHCPEnabled:{0}", ManObj
("DHCPEnabled"))), __IpNode, _
_GatewayNode, _
_DNSNode _
})
End If
_ParenNode.ExpandAll()
Me.tvInfo.Nodes.Add
(_ParenNode)Next
Catch ex As Exception
MsgBox(ex.Message,
MsgBoxStyle.Exclamation)End Try
關于VB.NET中怎么實現網絡監控就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。