Beispiel #1
0
        /// <summary>
        /// 添加被禁止的ip
        /// </summary>
        /// <param name="info"></param>
        public void AddBannedIp(IpInfo info)
        {
            DbParameter[] parameters = {
                                         DbHelper.MakeInParam("@ip1",(DbType)SqlDbType.Int, 4, info.Ip1),
                                         DbHelper.MakeInParam("@ip2",(DbType)SqlDbType.Int, 4, info.Ip2),
                                         DbHelper.MakeInParam("@ip3",(DbType)SqlDbType.Int, 4, info.Ip3),
                                         DbHelper.MakeInParam("@ip4",(DbType)SqlDbType.Int, 4, info.Ip4),
                                         DbHelper.MakeInParam("@admin",(DbType)SqlDbType.NVarChar,50,info.Username),
                                         DbHelper.MakeInParam("@dateline",(DbType)SqlDbType.NVarChar,50,info.Dateline),
                                         DbHelper.MakeInParam("@expiration",(DbType)SqlDbType.NVarChar,50,info.Expiration)
                                       };

            string sql = string.Format("INSERT INTO [{0}banned](ip1,ip2,ip3,ip4,admin,dateline,expiration) VALUES(@ip1,@ip2,@ip3,@ip4,@admin,@dateline,@expiration)",
                                        BaseConfigs.GetTablePrefix);
            DbHelper.ExecuteNonQuery(CommandType.Text, sql, parameters);
        }
Beispiel #2
0
        /// <summary>
        /// 添加被禁止的ip
        /// </summary>
        /// <param name="ip1">ip段</param>
        /// <param name="ip2">ip段</param>
        /// <param name="ip3">ip段</param>
        /// <param name="ip4">ip段</param>
        /// <param name="username">添加人</param>
        /// <param name="deteline">起始时间</param>
        /// <param name="expiration">过期时间</param>
        public static void AddBannedIp(string ipkey, Double deteline, string username)
        {
            string[] ip = ipkey.Split('.');
            deteline = deteline == 0 ? 1 : Math.Round(deteline);

            if ((Utils.StrToInt(ip[0], 0) < 255 || Utils.StrToInt(ip[1], 0) < 255 || Utils.StrToInt(ip[2], 0) < 255 || Utils.StrToInt(ip[3], 0) < 255) && (ip[0] != "0" && ip[1] != "0" && ip[2] != "0" && ip[3] != "0"))
            {
                IpInfo info = new IpInfo();
                info.Ip1 = TypeConverter.StrToInt(ip[0]);
                info.Ip2 = TypeConverter.StrToInt(ip[1], 0);
                info.Ip3 = TypeConverter.StrToInt(ip[2], 0);
                info.Ip4 = TypeConverter.StrToInt(ip[3], 0);
                info.Username = username;
                info.Dateline = DateTime.Now.ToShortDateString();
                info.Expiration = DateTime.Now.AddDays(deteline).ToString("yyyy-MM-dd"); ;
                SAS.Data.DataProvider.Ips.AddBannedIp(info);
            }
        }
Beispiel #3
0
 private static List<IpInfo> GetIpInfoList(IDataReader reader)
 {
     List<IpInfo> list = new List<IpInfo>();
     while (reader.Read())
     {
         IpInfo ipinfo = new IpInfo();
         ipinfo.Id = TypeConverter.ObjectToInt(reader["bdid"], 0);
         ipinfo.Ip1 = TypeConverter.ObjectToInt(reader["ip1"], 0);
         ipinfo.Ip2 = TypeConverter.ObjectToInt(reader["ip2"], 0);
         ipinfo.Ip3 = TypeConverter.ObjectToInt(reader["ip3"], 0);
         ipinfo.Ip4 = TypeConverter.ObjectToInt(reader["ip4"], 0);
         ipinfo.Username = reader["admin"].ToString();
         ipinfo.Dateline = Convert.ToDateTime(reader["dateline"].ToString()).ToString("yyyy-MM-dd");
         ipinfo.Expiration = Convert.ToDateTime(reader["expiration"].ToString()).ToString("yyyy-MM-dd");
         list.Add(ipinfo);
     }
     reader.Close();
     return list;
 }
Beispiel #4
0
 /// <summary>
 /// 添加被禁止的ip
 /// </summary>
 /// <param name="ip1">ip段</param>
 /// <param name="ip2">ip段</param>
 /// <param name="ip3">ip段</param>
 /// <param name="ip4">ip段</param>
 /// <param name="username">添加人</param>
 /// <param name="deteline">起始时间</param>
 /// <param name="expiration">过期时间</param>
 public static void AddBannedIp(IpInfo info)
 {
     DatabaseProvider.GetInstance().AddBannedIp(info);
 }
Beispiel #5
0
 private static string GetLocation(IpInfo info)
 {
     string ip = string.Format("{0}.{1}.{2}.{3}", info.Ip1, info.Ip2, info.Ip3, info.Ip4);
     SAS.Logic.IpSearch.PHCZIP phczip = new IpSearch.PHCZIP();
     return phczip.GetAddressWithIP(ip) == "" ? "未知地址" : phczip.GetAddressWithIP(ip);
 }