/// <summary> /// 开始拨号 /// </summary> /// <param name="ADSL_Name">宽带连接名称</param> /// <param name="ADSL_UserName">宽带连接用户名</param> /// <param name="ADSL_PassWord">宽带连接密码</param> public static void ChangeIp(String ADSL_Name = "宽带连接", String ADSL_UserName = "******", String ADSL_PassWord = "******") { sb.Clear(); sb.AppendLine("@echo off"); sb.AppendLine("set adslmingzi=" + ADSL_Name); sb.AppendLine("set adslzhanghao=" + ADSL_UserName); sb.AppendLine("set adslmima=" + ADSL_PassWord); sb.AppendLine("@Rasdial %adslmingzi% /disconnect"); sb.AppendLine("ping 127.0.0.1 -n 2"); sb.AppendLine("Rasdial %adslmingzi% %adslzhanghao% %adslmima%"); sb.AppendLine("echo 连接中"); sb.AppendLine("ping 127.0.0.1 -n 2"); sb.AppendLine("ipconfig"); // sb.AppendLine("pause"); using (StreamWriter sw = new StreamWriter(temppath, false, Encoding.Default)) { sw.Write(sb.ToString()); } Process.Start(temppath); System.Threading.Thread.Sleep(delay * 1000); int i = 0; while (!HttpMethod.CheckIp(null)) { Process.Start(temppath); System.Threading.Thread.Sleep((++i) * delay * 1000); } File.Delete(temppath); }
/// <summary> /// 验Ip线程函数 /// </summary> /// <param name="index">代理ip地址在APIList中的索引</param> /// <param name="checknum">验ip线程数</param> public static void IPCheckFunc(int index = 1, int checknum = 100) { String API_Url = API_Url_List[index]; var ips = HttpMethod.InputApi(API_Url); Task[] tarr = new Task[checknum]; Task.Factory.StartNew(() => { while (IPCheckStack.Count < 1000) { if (ips.Count == 0) { ips = HttpMethod.InputApi(API_Url); } Thread.Sleep(5000); } }); for (int i = 0; i < checknum; i++) { tarr[i] = Task.Factory.StartNew(() => { while (true) { if (IPCheckStack.Count < 200) { String ip = String.Empty; if (ips.TryPop(out ip)) { if (HttpMethod.CheckIp(ip)) { IPCheckStack.Push(ip); } } else { Thread.Sleep(1000); } } else { Thread.Sleep(5000); } } }); } }