从VB.Net获取TCP / IP详细信息 [英] Get TCP/IP details from VB.Net
问题描述
大家好,
我需要一些参考来获取完整的TCP / IP详细信息。目前我能够获得IP地址,子网掩码和网关。但我无法获得DNS。来自DNS的值能够获得,但显示失败。以下是我的代码。我正在运行VB.Net Windows Form Application 2008.请试一试,帮我找到这个。
Hi all,
I need some reference to get the full TCP/IP details. Currently I'm able to get the IP Address, Subnet Mask and Gateway. But I'm not able to get the DNS. The value from DNS is able to get but to display is failed. Below are my code. I'm running on VB.Net Windows Form Application 2008. Please have a try and help me to find this.
Imports System.Net
Imports System.Net.NetworkInformation
Public Class Form1
Private strEvents As String
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim Interfaces As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
Dim adapter As NetworkInterface
Dim myAdapterProps As IPInterfaceProperties = Nothing
Dim myGateways As GatewayIPAddressInformationCollection = Nothing
For Each adapter In Interfaces
If adapter.NetworkInterfaceType = NetworkInterfaceType.Loopback Then
Continue For
End If
TextBox1.AppendText(adapter.Name & Environment.NewLine)
TextBox1.AppendText(adapter.Description & Environment.NewLine)
myAdapterProps = adapter.GetIPProperties
myGateways = myAdapterProps.GatewayAddresses
Dim IPInfo As UnicastIPAddressInformationCollection = adapter.GetIPProperties().UnicastAddresses
Dim properties As IPInterfaceProperties = adapter.GetIPProperties()
For Each IPAddressInfo As UnicastIPAddressInformation In IPInfo
TextBox1.AppendText("IP Address : " & IPAddressInfo.Address.ToString & Environment.NewLine)
TextBox1.AppendText("Subnet Mask :" & IPAddressInfo.IPv4Mask.ToString & Environment.NewLine)
Next
For Each Gateway As GatewayIPAddressInformation In myGateways
TextBox1.AppendText("Gateway IP :" & Gateway.Address.ToString & Environment.NewLine)
Next
TextBox1.AppendText("DNS Address :" & properties.DnsAddresses.ToString & Environment.NewLine)
Next
End Sub
End Class
显示断点DNS地址并悬停在DnsAddresses的properties.DnsAddresses.ToString处。在结果中,有我想要显示的DNS地址。有人可以帮帮我吗?
Breakpoint on displaying DNS address and hover at "properties.DnsAddresses.ToString" at DnsAddresses. At Result, there are the DNS address which I want to display. Can someone help me?
推荐答案
IPInterfaceProperties.DnsAddresses
末尾的s是一个线索,可能有不止一个,MSDN文档备份了: http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipinterfaceproperties.dnsaddresses(v = vs.110).aspx [ ^ ]
这是一个收藏:只是在它上面调用ToString将不会返回所有条目,只是看着你的iPod将所有的MP3文件直接列入你的大脑 - 你必须遍历集合并查看每个条目。尝试另一个For Each循环:链接提供了一个示例。
The "s" at the end ofIPInterfaceProperties.DnsAddresses
is a clue that there may be more than one, and the MSDN documentation backs that up: http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipinterfaceproperties.dnsaddresses(v=vs.110).aspx[^]
It's a Collection: just calling ToString on it will not return all entries, any more than just looking at your iPod will list all the MP3 files directly into your brain - you have to iterate through the collection and look at each entry. Try another For Each loop: the link provides an example.
这篇关于从VB.Net获取TCP / IP详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!