IPCNTool.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Azylee.Core.DataUtils.StringUtils;
  2. using Azylee.Jsons;
  3. using Azylee.YeahWeb.HttpUtils;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Text;
  9. namespace Azylee.YeahWeb.ExtWebAPI.IPCNAPI
  10. {
  11. public static class IPCNTool
  12. {
  13. const string URL = "https://www.ip.cn/api/index?ip=&type=0";
  14. /// <summary>
  15. /// 获取IP地址信息
  16. /// </summary>
  17. /// <returns></returns>
  18. public static Tuple<string, string> Get()
  19. {
  20. try
  21. {
  22. CookieCollection cookie = new CookieCollection();
  23. string rss1 = HttpToolPlus.Get(URL, ref cookie);
  24. Dictionary<string, string> model = Json.String2Object<Dictionary<string, string>>(rss1);
  25. string ip = "", address = "";
  26. if (model.TryGetValue("ip", out string _ip)) ip = _ip;
  27. if (model.TryGetValue("address", out string _address)) address = _address;
  28. return new Tuple<string, string>(ip, address);
  29. }
  30. catch (Exception e) { return null; }
  31. }
  32. }
  33. }