// 添加一次失败验证次数 public static void failOne(string f, string ip) { mban.WaitOne(); Hashtable iplist = IPDATA.getAllData(f); Object o = iplist[ip]; if (o != null) { IPDATA od = (IPDATA)o; DateTime ndt = DateTime.Now.Date; if (!od.dt.Equals(ndt)) { od.failTimes = 0; } ++od.failTimes; od.dt = ndt; } else { o = iplist[ip] = new IPDATA(); IPDATA od = (IPDATA)o; od.ip = ip; ++od.failTimes; od.dt = DateTime.Now.Date; } IPDATA.saveAllData(f, iplist); mban.ReleaseMutex(); }
/// <summary> /// 返回一个表 /// </summary> /// <param name="f"></param> /// <returns></returns> public static Hashtable getAllData(string f) { Hashtable t = new Hashtable(); try{ string [] ips = File.ReadAllLines(f); foreach (string data in ips) { IPDATA a = new IPDATA(data); t[a.ip] = a; } } catch { } return(t); }
// 解锁 public static void clear(string f, string ip) { mban.WaitOne(); Hashtable iplist = IPDATA.getAllData(f); Object o = iplist[ip]; if (o != null) { IPDATA od = (IPDATA)o; od.failTimes = 0; od.dt = DateTime.Now.Date; } IPDATA.saveAllData(f, iplist); mban.ReleaseMutex(); }
// 获取已失败次数 public static int getFailTimes(string f, string ip) { int times = 0; mban.WaitOne(); Hashtable iplist = IPDATA.getAllData(f); Object o = iplist[ip]; if (o != null) { IPDATA od = (IPDATA)o; times = od.failTimes; } mban.ReleaseMutex(); return(times); }