/// 设置为无效ip /// </summary> /// <param name="curIPProxy"></param> public void SetUnviableIP(IPProxy _curIPProxy) { if (_curIPProxy != null) { var hitIpObj = IPProxyList.Where(c => c.IP == _curIPProxy.IP && c.Port == _curIPProxy.Port && c.Unavaiable == false).FirstOrDefault(); if (hitIpObj != null) { hitIpObj.Unavaiable = true; curIPProxy = null; GetIPProxy(); } } }
/// <summary> /// 随机获取一个IPProxy /// </summary> /// <returns></returns> public IPProxy GetIPProxy() { if (IPProxyList == null || IPProxyList.Count() <= 0) { return(null); } if (curIPProxy != null && curIPProxy.Unavaiable == false) { return(curIPProxy); } else { //添加代理ip列表,随机挑选ip var avaiableIpList = IPProxyList.Where(c => c.Unavaiable == false).ToList(); if (avaiableIpList.Count() > 0) { var rnd = new Random(); var index = rnd.Next(0, avaiableIpList.Count() - 1); curIPProxy = avaiableIpList[index]; return(curIPProxy); } return(null); } }