How to get the IP addresses of computers connected to my computer using C # without using the ping method

I want to get the IP addresses of all computers connected to the computer using C #, but I do not want to use the Ping method, because it takes a lot of time, especially when the range of IP addresses is very wide.

+5
source share
1 answer

Retrieving All Active TCP Connections

Use the IPGlobalProperties.GetActiveTcpConnections method

using System.Net.NetworkInformation; public static void ShowActiveTcpConnections() { Console.WriteLine("Active TCP Connections"); IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); TcpConnectionInformation[] connections = properties.GetActiveTcpConnections(); foreach (TcpConnectionInformation c in connections) { Console.WriteLine("{0} <==> {1}", c.LocalEndPoint.ToString(), c.RemoteEndPoint.ToString()); } } 

A source:
https://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipglobalproperties.getactivetcpconnections.aspx

Note: This gives you only active TCP connections .


A shorter version of the code above.

 foreach (var c in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections()) { ... } 

Retrieving all networked computers

Better to do a ping scroll. It takes a few seconds to complete 254 IP addresses. The solution is here fooobar.com/questions/300595 / ...

+7
source

Source: https://habr.com/ru/post/1268380/


All Articles