网络的IP地址 [英] IP Addresses for network
问题描述
我在VB中有一个项目,我正在尝试获取网络上所有其他计算机的所有IPv4地址。我有这个代码,但它似乎没有工作,因为它获得IPv6。
<前lang =vb> Dim _IPHostEntry As Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
对于 每个 ipadds As Net .IPAddress
在 _IPHostEntry.AddressList
ListBox1.Items.Add(ipadds)
下一步
请帮助。
引用:如果我在cmd.exe中键入netstat,我会得到什么IPv4。
所以netstat [ ^ ]不带参数使用,显示活动的TCP连接。
使用 IPGlobalProperties.GetActiveTcpConnections方法 [< a href =http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipglobalproperties.getactivetcpconnections.aspxtarget =_ blanktitle =New Window> ^ ]获取机器的所有连接。
进口系统
进口System.Net
进口System.Net.NetworkInformation
模块程序
Sub Main()
Dim ipProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()
Dim tcpConnections As TcpConnectionInformation()= ipProperties.GetActiveTcpConnections ()
For Each info As TcpConnectionInformation in tcpConnections
Cons ole.WriteLine(Local:& info.LocalEndPoint.Address.ToString()& :& info.LocalEndPoint.Port.ToString()& vbLf& 远程:& info.RemoteEndPoint.Address.ToString()& :& info.RemoteEndPoint.Port.ToString()& vbLf& 状态:& info.State.ToString()& vbLf& vbLf)
下一个
Console.ReadLine()
结束子
结束模块
您可以使用 AddressFamily [ ^ ]属性,仅过滤IPv4连接的连接。
I have a project in VB, and i am trying to get all the IPv4 addresses of all other computers on the network. I have this code but it does not seem to work as it gets IPv6.
Dim _IPHostEntry As Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
For Each ipadds As Net.IPAddress
In _IPHostEntry.AddressList
ListBox1.Items.Add(ipadds)
Next
Please Help.
Quote:What ever IPv4s I would get if I type in "netstat" in cmd.exe.
So netstat[^] used without parameters, displays active TCP connections.
Use IPGlobalProperties.GetActiveTcpConnections Method[^] to get all connections of your machine.
Imports System Imports System.Net Imports System.Net.NetworkInformation Module Program Sub Main() Dim ipProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties() Dim tcpConnections As TcpConnectionInformation() = ipProperties.GetActiveTcpConnections() For Each info As TcpConnectionInformation In tcpConnections Console.WriteLine("Local : " & info.LocalEndPoint.Address.ToString() & ":" & info.LocalEndPoint.Port.ToString() & vbLf & "Remote : " & info.RemoteEndPoint.Address.ToString() & ":" & info.RemoteEndPoint.Port.ToString() & vbLf & "State : " & info.State.ToString() & vbLf & vbLf) Next Console.ReadLine() End Sub End Module
You can use AddressFamily[^] property to filter connections for only IPv4 ones.
这篇关于网络的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!