RequestHelper.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace WebAPIBase.Utils
  8. {
  9. public class RequestHelper
  10. {
  11. /// <summary>
  12. /// 是否为远程服务器,DEBUG用
  13. /// </summary>
  14. public static bool IsRemote
  15. {
  16. get
  17. {
  18. string address = RequestHelper.GetServerIp();
  19. bool a = !address.Contains("192.168.") && !address.Contains("127.0.") && !address.Contains("2.0.");
  20. return a;
  21. }
  22. }
  23. static string serverIp;
  24. public static string GetServerIp()
  25. {
  26. if (string.IsNullOrEmpty(serverIp))
  27. {
  28. System.Net.IPAddress[] addressList = Dns.GetHostAddresses(Dns.GetHostName());
  29. string address = "";
  30. foreach (System.Net.IPAddress a in addressList)
  31. {
  32. if (a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
  33. {
  34. address = a.ToString();
  35. break;
  36. }
  37. }
  38. serverIp = address;
  39. }
  40. return serverIp;
  41. }
  42. }
  43. }