PDA

View Full Version : سوال: دسترسی به ip های سیستم



malaki.davud
دوشنبه 15 آبان 1391, 13:54 عصر
با سلام
من می خوام درون برنامه ام بتونم ip هایی که بر روی سیستم من ست شده رو بتونم بدست بیاورم
کسی راه حلی نداره
با تشکر

کامبیز اسدزاده
دوشنبه 15 آبان 1391, 15:01 عصر
public static string LocalIPAddress() { IPHostEntry host; string localIP = ""; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily.ToString() == "InterNetwork") { localIP = ip.ToString(); } } return localIP; }




String strHostName = string.Empty; // Getting Ip address of local machine... // First get the host name of local machine. strHostName = Dns.GetHostName(); Console.WriteLine("Local Machine's Host Name: " + strHostName); // Then using host name, get the IP address list.. IPHostEntry ipEntry = Dns.GetHostEntry(strHostName); IPAddress[] addr = ipEntry.AddressList; for (int i = 0; i < addr.Length; i++) { Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString()); } Console.ReadLine();