![](/img/trans.png)
[英]How to check PC is connected with Internet or Intranet without IP address and Ping method in C#?
[英]How to get the IP addresses of the machines are connected to my PC using without using ping methode C#
我想獲得使用C#連接到我的PC的所有機器的IP地址,但我不想使用Ping方法,因為它需要花費很多時間,特別是當IP地址的范圍非常寬時。
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());
}
}
注意:這僅為您提供活動的TCP連接 。
上面代碼的較短版本。
foreach (var c in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections())
{
...
}
做ping掃可能更好。 需要幾秒鍾才能完成254個ip地址。 解決方案在這里https://stackoverflow.com/a/4042887/3645638
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.