static void v5() { WebPageProxyProvider wppp = new WebPageProxyProvider(); wppp.Sources.Add(new WebPageProxySource { URL = "http://proxy.ipcn.org/proxylist.html", Pattern = @"(?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s*):(?<port>\s*\d{1,5})" }); ProxyValidator pv = new ProxyValidator(); ProxyValidateCondition vc = new ProxyValidateCondition(); vc.Url = "http://www.baidu.com"; vc.Keywords.Add("百度"); vc.Keywords.Add("html"); pv.ValidateConditions.Add(vc); pm = new ProxyManager(); pm.ProxyProviders.Add(wppp); pm.ProxyValidator = pv; pm.ProxyValidator.ValidateConditions.Add(vc); pm.StartDownloadProxies(false); Thread.Sleep(10000); pm.CancelValidation(); }
private void SaveProxyValidations() { List <ProxyValidateCondition> conditions = new List <ProxyValidateCondition>(); foreach (DataRow row in proxyValidateConditionTable.Rows) { ProxyValidateCondition pvc = new ProxyValidateCondition(); pvc.Url = row["TargetURL"].ToString(); string[] keywords = row["Keywords"].ToString().Split(new char[] { ',', ';', ',', ';' }); pvc.Keywords.AddRange(keywords); string[] forbiddenKeywords = row["ForbiddenKeywords"].ToString().Split(new char[] { ',', ';', ',', ';' }); pvc.ForbiddenKeywords.AddRange(forbiddenKeywords); conditions.Add(pvc); } ins.ProxyManager.ProxyValidator.ReplaceProxyValidations(conditions); bool success = ins.SaveProxyValidateConditionConfig(); ResetProxyValidateCondition(); if (success) { MessageBox.Show("Done"); } else { MessageBox.Show("Failed"); } }
static void v8() { ManualResetEvent mre = new ManualResetEvent(false); l = new Listener(); SelectiveProxyGuide spg = new SelectiveProxyGuide(); spg.DnsCache = new DNSCache(); spg.PacSetting = new PacSetting(); // spg.PacSetting.AddURLPattern(@"http://.*\.baidu\.com"); pm = new ProxyManager(); WebPageProxyProvider wppp = new WebPageProxyProvider(); wppp.Sources.Add(new WebPageProxySource { URL = "http://proxy.ipcn.org/proxylist.html", Pattern = @"(?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s*):(?<port>\s*\d{1,5})" }); pm.ProxyProviders.Add(wppp); ProxyValidator pv = new ProxyValidator(); ProxyValidateCondition vc = new ProxyValidateCondition(); vc.Url = "http://www.baidu.com"; vc.Keywords.Add("百度"); vc.Keywords.Add("html"); pv.ValidateConditions.Add(vc); pm.ProxyValidator = pv; spg.ProxyManager = pm; l.TargetConnctionGuide = spg; pm.StartDownloadProxies(false); l.StartListener(); mre.WaitOne(); }
public static IEnumerable <ProxyValidateCondition> ReadConfig(string path) { List <ProxyValidateCondition> conditions = new List <ProxyValidateCondition>(); XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNodeList nodelist = doc.SelectNodes("//ProxyValidateCondition"); if (nodelist == null) { return(conditions); } foreach (XmlNode node in nodelist) { if (node.Attributes == null) { continue; } XmlAttribute urlX = node.Attributes["URL"]; XmlAttribute keywordX = node.Attributes["Keywords"]; XmlAttribute forbiddenKeywordX = node.Attributes["ForbiddenKeywords"]; if (urlX == null || keywordX == null || forbiddenKeywordX == null) { continue; } ProxyValidateCondition pvc = new ProxyValidateCondition { Url = urlX.Value, }; pvc.Keywords.AddRange(keywordX.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); pvc.ForbiddenKeywords.AddRange(forbiddenKeywordX.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); conditions.Add(pvc); } return(conditions); }