/// <param name="iNewIpFrequency">Temps en minutes</param> public WebQueryHideIP(ProgressCancelNotifier iProgressCancelNotifier, bool iWithSafeNetwork, bool iWithIpCheck = true, int iNewIpFrequency = 30) : base(iProgressCancelNotifier) { if (ProcessTools.IsProcessRunning("privoxy") == false) { throw new Exception("Pour effectuer des requetes via proxy, le logiciel 'Privoxy' doit être lancé."); } if (ProcessTools.IsProcessRunning("vidalia") == false) { throw new Exception("Pour effectuer des requetes via proxy, le logiciel 'Vidalia' doit être lancé."); } WebQueryType = WebQueryTypeEnum.WebQueryWithProxy; newIpFrequency = iNewIpFrequency; proxyAdress = PROXYADRESS; proxyPort = PROXYPORT; socksAdress = SOCKSADRESS; socksPort = SOCKSPORT; socksPassword = SOCKSPASSWORD; WithSafeNetwork = iWithSafeNetwork; //Chargement de la liste de user agent userAgentList.Add("Mozilla/5.0 (compatible; MSIE 9.0; AOL 9.7; AOLBuild 4343.19; Windows NT 6.1; WOW64; Trident/5.0; FunWebProducts)"); userAgentList.Add("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"); userAgentList.Add("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36"); userAgentList.Add("Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"); userAgentList.Add("Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14"); userAgentList.Add("Mozilla/5.0 (X11; U; Linux i686; fr-fr) AppleWebKit/525.1+ (KHTML, like Gecko, Safari/525.1+) midori/1.19"); //vérification de l'adresse proxy différente de l'adresse réel: if (iWithIpCheck) { string realIp = new WebQueryNoHideIP(Notifier, iWithSafeNetwork).GetMyIp(); string proxyIp = GetMyIp(); if (proxyIp != null && realIp != null && proxyIp != realIp) { using (var sublevel1 = new ProgressCancelNotifier.SubLevel(Notifier)) { Notifier.Report("Ip proxy : {0}, Ip box : {1} ".FormatString(proxyIp, realIp)); } } else { throw new Exception("Error lors de la vérification du proxy. Vérifier si le socks(vidalia) et le proxy(privoxy) sont bien démarrés."); } } }
public bool NewIp() { string currentIp = CurrentIp; var NewIpLock = new object(); lock (NewIpLock) { //gestion du multithreading if (currentIp != CurrentIp) { return(true); } IPEndPoint ip = new IPEndPoint(IPAddress.Parse(socksAdress), socksPort); Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { client.Connect(ip); } catch (SocketException e) { MessageBox.Show("Unable to connect to server of Tor." + e.Message); return(false); } client.Send(Encoding.ASCII.GetBytes("AUTHENTICATE \"" + socksPassword + "\"\n")); byte[] data = new byte[1024]; int receivedDataLength = client.Receive(data); string stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); if (stringData.Contains("250")) { client.Send(Encoding.ASCII.GetBytes("SIGNAL NEWNYM\r\n")); data = new byte[1024]; receivedDataLength = client.Receive(data); stringData = Encoding.ASCII.GetString(data, 0, receivedDataLength); if (!stringData.Contains("250")) { MessageBox.Show("Unable to signal new user to server of Tor."); client.Shutdown(SocketShutdown.Both); client.Close(); return(false); } } else { MessageBox.Show("Unable to authenticate to server of Tor."); client.Shutdown(SocketShutdown.Both); client.Close(); return(false); } client.Shutdown(SocketShutdown.Both); client.Close(); dateLastResetIp = DateTime.Now; using (var level1 = new ProgressCancelNotifier.SubLevel(Notifier)) { Notifier.Report(new Progress() { Message = "Nouvelle ip : " + GetMyIp() }); } return(true); } }