本文介绍了网络的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在VB中有一个项目,我正在尝试获取网络上所有其他计算机的所有IPv4地址。我有这个代码,但它似乎没有工作,因为它获得IPv6。 Dim _IPHostEntry As Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName) 对于 每个 ipadds As Net .IPAddress 在 _IPHostEntry.AddressList ListBox1.Items.Add(ipadds) 下一步 请帮助。解决方案 所以netstat [ ^ ]不带参数使用,显示活动的TCP连接。 使用 IPGlobalProperties.GetActiveTcpConnections方法 [ ^ ]获取机器的所有连接。 进口系统进口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) NextPlease Help. 解决方案So netstat[^] used without parameters, displays active TCP connections.Use IPGlobalProperties.GetActiveTcpConnections Method[^] to get all connections of your machine.Imports SystemImports System.NetImports System.Net.NetworkInformationModule ProgramSub Main()Dim ipProperties As IPGlobalProperties = IPGlobalProperties.GetIPGlobalProperties()Dim tcpConnections As TcpConnectionInformation() = ipProperties.GetActiveTcpConnections()For Each info As TcpConnectionInformation In tcpConnectionsConsole.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)NextConsole.ReadLine()End SubEnd ModuleYou can use AddressFamily[^] property to filter connections for only IPv4 ones. 这篇关于网络的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 16:01