using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.NetworkInformation; using System.Net; namespace CSHigher { public class ShowIp { public static void Main() { EnumComputers(); Console.ReadLine(); } private static void EnumComputers() { try { for (int i = 1; i <= 255; i++) { Ping myPing; myPing = new Ping(); myPing.PingCompleted += new PingCompletedEventHandler(_myPing_PingCompleted); string pingIP = "192.168.163." + i.ToString(); myPing.SendAsync(pingIP, 1000, null); } } catch { } } private static void _myPing_PingCompleted(object sender, PingCompletedEventArgs e) { try { if (e.Reply.Status == IPStatus.Success) { Console.WriteLine(e.Reply.Address.ToString() + " " + Dns.GetHostByAddress(IPAddress.Parse(e.Reply.Address.ToString())).HostName); } } catch { } } } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/58347.html