IP操作类
后端操作Ip
IpHelper.cs
1 namespace SH3H.NC.Common.HttpHelper 2 { 3 /// <summary> 4 /// 共用工具类 5 /// </summary> 6 public static class IpHelper 7 { 8 #region 获得用户IP 9 /// <summary> 10 /// 获得用户IP 11 /// </summary> 12 public static string GetUserIp() 13 { 14 string ip; 15 string[] temp; 16 bool isErr = false; 17 if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"] == null) 18 ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); 19 else 20 ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"].ToString(); 21 if (ip.Length > 15) 22 isErr = true; 23 else 24 { 25 temp = ip.Split('.'); 26 if (temp.Length == 4) 27 { 28 for (int i = 0; i < temp.Length; i++) 29 { 30 if (temp[i].Length > 3) isErr = true; 31 } 32 } 33 else 34 isErr = true; 35 } 36 37 if (isErr) 38 return "1.1.1.1"; 39 else 40 return ip; 41 } 42 #endregion 43 44 45 46 } 47 }
我佛真的不渡哈批

浙公网安备 33010602011771号