这篇文章给大家介绍VB.NET中怎么实现网络监控,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
在窗体上放置一个TreeView控件,改名为tvInfo。
再放置一个按钮控件。
双击按钮,编写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) Then
For 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) Then
For 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) Then
For 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中怎么实现网络监控就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。