这篇文章给大家介绍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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。