public void addRerouteItem(string url) { if (isRerouting) { // check no duplicate bool found = false; lock (_LOCK) { foreach (RouteItem rItem in changedRoutes) { if (rItem.URL == url) { found = true; break; } } if (!found) { RouteItem newItem = new RouteItem(url); changedRoutes.Add(newItem); List <String> results = DnsFuncs.GetDnsRecords(url, false); foreach (string ipAddress in results) { if (newItem.AddIpAddress(IPAddress.Parse(ipAddress))) { RouteInterop.AddRoute(ipAddress.Trim(), "255.255.255.255", gateway.ToString(), gatewayIndex); } } } } } }
void AddRerouteByDNSName(string name) { var results = DnsFuncs.GetDnsRecords(name); foreach (string ipAddress in results) { /*System.Diagnostics.Process process = new System.Diagnostics.Process(); * System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); * startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; * startInfo.FileName = "cmd.exe"; * startInfo.Arguments = "/C route add " + ipAddress.Trim() + " mask 255.255.255.255 " + gateway; * startInfo.Verb = "runas"; * process.StartInfo = startInfo; * process.Start(); * process.WaitForExit();*/ RouteInterop.AddRoute(ipAddress.Trim(), "255.255.255.255", gateway.ToString(), gatewayIndex); } }
public void RerouteNetflix() { if (isRerouting) { foreach (IPAddressRange range in netflixRanges) { RouteInterop.AddRoute(range.ipAddressLower, range.mask, gateway, gatewayIndex); } lock (_LOCK) { addRerouteItem("netflix.com"); addRerouteItem("nflxext.com"); } // Go ahead and ping these urls so they go in cache DnsFuncs.GetDnsRecords("secure.netflix.com", false); DnsFuncs.GetDnsRecords("codex.nflxext.com", false); DnsFuncs.GetDnsRecords("assets.nflxext.com", false); DnsFuncs.GetDnsRecords("api-global.netflix.com", false); DnsFuncs.GetDnsRecords("customerevents.netflix.com", false); } }
void CheckDNSCache() { System.Diagnostics.Process process = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C ipconfig /displaydns"; startInfo.CreateNoWindow = true; //startInfo.Verb = "runas"; process.StartInfo = startInfo; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.Start(); string output = process.StandardOutput.ReadToEnd(); process.WaitForExit(); var result = output.Split(new[] { '\r', '\n' }); bool netflixSpotted = false; string cname = null; RouteItem currItem = null; foreach (string line in result) { if (line.Length > 20) { string trimmedLine = line.Trim(); if (trimmedLine.Substring(0, 11) == "Record Name") { if (cname != null) { netflixSpotted = trimmedLine.Contains(cname); } else { /*netflixSpotted = trimmedLine.Contains("netflix.com") || trimmedLine.Contains("nflxext.com"); * * StringCollection urls = Properties.Settings.Default.rerouteURLs;*/ lock (_LOCK) { foreach (RouteItem rItem in changedRoutes) { int index = trimmedLine.IndexOf(rItem.URL); if (index > 0) { if (trimmedLine[index - 1] == '.' || trimmedLine[index - 1] == ' ') { netflixSpotted = true; currItem = rItem; break; } } /*if (trimmedLine.Contains(rItem.URL)) * { * netflixSpotted = true; * currItem = rItem; * break; * }*/ } } } } else if (netflixSpotted) { if (trimmedLine.Substring(0, 12) == "CNAME Record") { cname = trimmedLine.Split(':')[1].Trim(); netflixSpotted = false; } if (trimmedLine.Substring(0, 15) == "A (Host) Record") { cname = null; var split = trimmedLine.Split(':'); if (split.Count <string>() == 2) // not ipv6 { /*process = new System.Diagnostics.Process(); * startInfo = new System.Diagnostics.ProcessStartInfo(); * startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; * startInfo.FileName = "cmd.exe"; * startInfo.Arguments = "/C route add " + split[1].Trim() + " mask 255.255.255.255 " + gateway; * startInfo.Verb = "runas"; * process.StartInfo = startInfo; * process.Start(); * process.WaitForExit();*/ string newIp = split[1].Trim(); if (currItem != null) { // if not added if (currItem.AddIpAddress(IPAddress.Parse(newIp))) { RouteInterop.AddRoute(split[1].Trim(), "255.255.255.255", gateway.ToString(), gatewayIndex); } else { int i = 0; } } netflixSpotted = false; currItem = null; } } } } } /*var results = DnsFuncs.GetDnsTable(); * * foreach (string ipAddress in results) * { * RouteInterop.AddRoute(ipAddress.Trim(), "255.255.255.255", gateway.ToString(), gatewayIndex); * } * * AddRerouteByDNSName("netflix.com"); * AddRerouteByDNSName("www.netflix.com"); * AddRerouteByDNSName("secure.netflix.com"); * AddRerouteByDNSName("codex.nflxext.com"); * AddRerouteByDNSName("assets.nflxext.com"); * AddRerouteByDNSName("api-global.netflix.com"); * AddRerouteByDNSName("customerevents.netflix.com");*/ }