NetHelper.cs 476 B

12345678910111213141516171819202122
  1. using System.Collections.Generic;
  2. using System.Net;
  3. namespace Base
  4. {
  5. public static class NetHelper
  6. {
  7. public static string[] GetAddressIPs()
  8. {
  9. //获取本地的IP地址
  10. List<string> addressIPs = new List<string>();
  11. foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
  12. {
  13. if (address.AddressFamily.ToString() == "InterNetwork")
  14. {
  15. addressIPs.Add(address.ToString());
  16. }
  17. }
  18. return addressIPs.ToArray();
  19. }
  20. }
  21. }