Command_Function.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*******************************************************************************
  2. * iNethinkCMS - 网站内容管理系统
  3. * Copyright (C) 2012-2013 inethink.com
  4. *
  5. * @author jackyang <69991000@qq.com>
  6. * @website http://cms.inethink.com
  7. * @version 1.3.6.0 (2013-08-14)
  8. *
  9. * This is licensed under the GNU LGPL, version 3.0 or later.
  10. * For details, see: http://www.gnu.org/licenses/gpl-3.0.html
  11. *******************************************************************************/
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Text;
  15. namespace iNethinkCMS.Command
  16. {
  17. public class Command_Function
  18. {
  19. #region 获得用户IP
  20. /// <summary>
  21. /// 获得用户IP
  22. /// </summary>
  23. public static string GetUserIp()
  24. {
  25. string ip;
  26. string[] temp;
  27. bool isErr = false;
  28. if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"] == null)
  29. ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
  30. else
  31. ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"].ToString();
  32. if (ip.Length > 15)
  33. isErr = true;
  34. else
  35. {
  36. temp = ip.Split('.');
  37. if (temp.Length == 4)
  38. {
  39. for (int i = 0; i < temp.Length; i++)
  40. {
  41. if (temp[i].Length > 3) isErr = true;
  42. }
  43. }
  44. else
  45. isErr = true;
  46. }
  47. if (isErr)
  48. return "0.0.0.0";
  49. else
  50. return ip;
  51. }
  52. #endregion
  53. /// <summary>
  54. /// 判断是否外部提交
  55. /// </summary>
  56. public static bool Fun_CheckPost()
  57. {
  58. string server_v1 = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_REFERER"]);
  59. string server_v2 = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"]);
  60. int changdu = server_v2.Length;
  61. if (server_v1.Substring(7, changdu) != server_v2)
  62. {
  63. return true;
  64. }
  65. else
  66. {
  67. return false;
  68. }
  69. }
  70. }
  71. }