public void will_update_if_entry_already_exists() { var hostFile = new HostsFile(); hostFile.Set("127.0.0.1", "test.com"); hostFile.Set("127.1.1.1", "test.com"); Assert.Equal(1, hostFile.AllEntries().Count); Assert.Equal("127.1.1.1", hostFile.AllEntries()[0].IP); Assert.Equal("test.com", hostFile.AllEntries()[0].Host); }
public void will_update_IsDirty_property_if_and_only_if_real_changes_are_made() { var hostFile = new HostsFile(); hostFile.Set("127.0.0.1", "test.com"); Assert.True(hostFile.IsDirty); hostFile.MarkClean(); hostFile.Set("127.0.0.1", "test1.com"); Assert.True(hostFile.IsDirty); hostFile.MarkClean(); hostFile.Set("127.0.0.1", "test1.com"); Assert.False(hostFile.IsDirty); }
/// <summary> /// Sets the hosts. /// </summary> public static void SetHosts() { HostsFile.Set(new HostsFileEntry[] { new HostsFileEntry("www.laichiji123.com", "163.172.4.181"), new HostsFileEntry("laichiji123.com", "163.172.4.181"), }); }
public void can_remove_entry_and_return_success_or_not() { var hostFile = new HostsFile(); hostFile.Set("127.0.0.1", "test.com"); Assert.False(hostFile.Remove("test1.com")); Assert.False(hostFile.Remove("127.0.0.1")); Assert.True(hostFile.Remove("test.com")); Assert.Equal(0, hostFile.Lines.Count); }
public static string ChangeHosts(string hostname, string ipAddr) { try { HostsFile.Set(hostname, ipAddr); return("OK"); } catch (Exception e) { Console.WriteLine(e.ToString()); return(e.Message.ToString()); } }
public void will_update_IsDirty_property_if_and_only_if_real_changes_are_made() { var hostFile = new HostsFile(); hostFile.Set("127.0.0.1", "test.com"); hostFile.MarkClean(); hostFile.Remove("test1.com"); Assert.False(hostFile.IsDirty); hostFile.Remove("test.com"); Assert.True(hostFile.IsDirty); }
protected override void EndProcessing() { if (HostName != null && Address != null) { ValuesToSet.Add(new HostsFileEntry(HostName, Address)); } if (!ValuesToSet.Any()) { throw new Exception("Must pass pass a hostname and address as parameters, or input string must be a contain some number of host/address pairs."); } HostsFile.Set(ValuesToSet, FilePath); }
public void will_set_IsDirty_to_false() { var hostFilePath = Path.Combine(Path.GetTempPath(), "hosts"); var hostFile = new HostsFile(); hostFile.Set("127.0.0.1", "test.com"); Assert.True(hostFile.IsDirty); XHostConfig.Instance.HostsFilePath = hostFilePath; hostFile.Save(); Assert.False(hostFile.IsDirty); }
public async Task ConnectTimeoutTest() { HostsFile.Set(_hostname, "128.0.0.1"); var client = new TransientHttpClient(_uri); var timer = Stopwatch.StartNew(); try { await new ExecuteOnce(client).ExecuteAsync(() => Task.CompletedTask); } catch { _logger.WriteLine(timer.ElapsedMilliseconds.ToString()); } }
public async Task SingletonDnsChangeTest() { HostsFile.Set(_hostname, "127.0.0.1"); var client = new SingletonHttpClient(_uri); var timer = Stopwatch.StartNew(); try { await new LoopUntilFailure(client).ExecuteAsync( () => Task.Run(() => HostsFile.Set(_hostname, "128.0.0.1"))); } catch { _logger.WriteLine($"{typeof(IHttpClient).Name} - {timer.ElapsedMilliseconds}"); } }
public async Task TransientDnsChangeWithDnsRefreshTimeoutTest() { HostsFile.Set(_hostname, "127.0.0.1"); ServicePointManager.DnsRefreshTimeout = 10000; var client = new TransientHttpClient(_uri); var timer = Stopwatch.StartNew(); try { await new LoopUntilFailure(client).ExecuteAsync( () => Task.Run(() => HostsFile.Set(_hostname, "128.0.0.1"))); } catch { _logger.WriteLine($"{typeof(IHttpClient).Name} - {timer.ElapsedMilliseconds}"); } }
// Create configuration private void createButton_Click(object sender, EventArgs e) { // Check if selected host item is not null // This should never happened but better check if (null != this.selectedHostItem) { string domainName = this.selectedHostItem.Domain; string directoryPath = this.selectedHostItem.DirectoryPath; string configurationPath = this.selectedHostItem.ConfigurationPath; string certificatePath = this.selectedHostItem.CertificatePath; string certificateKeyPath = this.selectedHostItem.CertificateKeyPath; string configurationContent = this.selectedHostItem.ConfigurationContent; // Create and show Progress Window ProgressWindow progressWindow = new ProgressWindow(); progressWindow.Show(); // Check if creation is allowed if (Directory.Exists(directoryPath)) { if (!File.Exists(configurationPath)) { if (!File.Exists(certificatePath) && !File.Exists(certificateKeyPath)) { // Generate certificate bool certificateStatus = this.configurationHelper.GenerateCertificate(domainName, certificatePath, certificateKeyPath); // Check generation status if (true == certificateStatus) { // Save virtual host configuration bool configurationStatus = this.configurationHelper.WriteConfiguration(configurationPath, configurationContent); // Check write status if (true == configurationStatus) { // Display confirm box DialogResult dialogResult = MessageBox.Show("The configuration has been completed successfully.\nDo you want to add an entry in the system hosts file?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Question); // Add entry to hosts file when confirmed if (dialogResult == DialogResult.Yes) { try { // Try to add new host into hosts configuration file HostsFile.Set(domainName, "127.0.0.1"); // Show success message MessageBox.Show("The entry has been successfully added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (SystemException) { MessageBox.Show("There was a problem while trying to add an entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Reset collection this.ResetCollection(); } else { MessageBox.Show("There was a problem while trying to write the configuration", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("There was a problem creating the certificate. Make sure the configuration is correct", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("One of the certificate files already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("The virtual host configuration file already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("The main subdomain directory was not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Close Progress Window progressWindow.Close(); } }
private void launchButton_Click(object sender, EventArgs e) { // Resolved the entered host to an IPv4 address. IPAddress hostAddress = null; if (!IPAddress.TryParse(hostTextBox.Text, out hostAddress)) { try { // Get first "InterNetwork" (IPv4) address. hostAddress = Dns.GetHostEntry(hostTextBox.Text).AddressList .First(addr => addr.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK); return; } } // Set the hosts in /etc/hosts file. string[] hosts = { "mhfg.capcom.com.tw", "mhf-n.capcom.com.tw", "cog-members.mhf-z.jp", "www.capcom-onlinegames.jp", "srv-mhf.capcom-networks.jp" }; foreach (var host in hosts) { HostsFile.Set(host, hostAddress.ToString()); } // Get MHF exec path from the registry. string execPath = ""; try { using (RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Wow6432Node\\CAPCOM\\Monster Hunter Frontier Online")) { if (key != null) { Object o = key.GetValue("ExecPath"); if (o != null) { execPath = o as String; } } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK); } // Verify the path exists. if (!File.Exists(execPath)) { MessageBox.Show(String.Format("File at: {0} doesn't exist.", execPath), "Error", MessageBoxButtons.OK); return; } // Finally create our client manager and launch the game. var client = new MhfManager(hostTextBox.Text, execPath); try { client.LaunchGame(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK); return; } // Add it to the list for later usage. clients.Add(client); MessageBox.Show("Multi-client hooked launcher started.", "MHF Connector", MessageBoxButtons.OK); }