//Process PAC URL and extract proxies public static List <ConfigPair> GetPAC(ConfigPair config) { #if DEBUG Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name); Console.WriteLine("Processing PAC: {0}", config.URL.ToString()); #endif List <ConfigPair> ret = new List <ConfigPair>(); try { string pacData = GetHTTP(config.URL, null, config.UserAgent); if (!pacData.Contains("PROXY ")) { return(ret); } System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex(@"PROXY (.*?):(\d+)"); System.Text.RegularExpressions.MatchCollection matches = rx.Matches(pacData); foreach (System.Text.RegularExpressions.Match match in matches) { Uri srv = string.Format("{0}:{1}", match.Groups[1].Value, match.Groups[2].Value).ToUri(); if (!ret.Any(x => x.URL.Equals(srv))) { //if winhttp convert to IE if (config.UserAgent.Equals(UserAgents.WHUA)) { config.UserAgent = UserAgents.EDUA; } ret.Add(new ConfigPair { URL = srv, UserAgent = config.UserAgent }); } } } catch (Exception ex) { #if DEBUG Console.WriteLine("[*] An exception occured: {0}", ex.Message); #endif } #if DEBUG Console.WriteLine("\tProxies: {0}", ret.Count); foreach (var proxy in ret) { Console.WriteLine("{0}", proxy); } #endif return(ret); }
//Get entries from the registry public static ConfigPair GetRegistry(string key, string value, string UA) { ConfigPair ret = null; try { var regkey = Registry.GetValue(key, value, null); if (regkey != null) { ret = new ConfigPair { URL = regkey.ToString().ToUri(), UserAgent = UA }; } } catch (Exception ex) { #if DEBUG Console.WriteLine("[*] An exception occured: {0}", ex); #endif } return(ret); }
public static bool DoHTTP(Uri url, string response, string info, ConfigPair config) { #if DEBUG Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name); #endif try { Uri urlrequest = new Uri(string.Format("{0}?{1}", url.ToString(), info)); var resp = GetHTTP(urlrequest, config.URL, config.UserAgent); if (!string.IsNullOrEmpty(resp)) { if (resp.Contains(response)) { #if DEBUG Console.WriteLine("\tCanTalk: true"); #endif return(true); } else { #if DEBUG Console.WriteLine("\tConnection success, but response not the same."); #endif return(false); } } return(false); } catch (Exception ex) { #if DEBUG Console.WriteLine("[*] An exception occured: {0}", ex); #endif return(false); } }
public static string GetHTTP(Uri url, ConfigPair config) { return(GetHTTP(url, config.URL, config.UserAgent)); }