VB.NET中怎么实现网络监控
这篇文章给大家介绍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
创建 DNS服务器地址 子节点
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中怎么实现网络监控就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
标题名称:VB.NET中怎么实现网络监控
标题来源:http://myzitong.com/article/ihchsp.html