水上骑兵 2010-01-12
VB.NET不但可以帮助开发人员实现各种硬件设备信息的产看等功能,还能通过它对网络进行监控。在这里我们就会为大家详细介绍有关VB.NET网络监控的相关操作方法,希望对初学者们有所帮助。
VB.NET网络监控的开发环境:Visual Studio.net 2005
1.在窗体上放置一个TreeView控件,改名为tvInfo。
2.再放置一个按钮控件。
3.双击按钮,编写VB.NET网络监控代码。
创建 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
创建 DNS服务器地址 子节点
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