// // called when the type field changes // private void typeBox_SelectedIndexChanged(object sender, System.EventArgs e) { browseList.Items.Clear(); if (browser != null) { browser.Dispose(); } nameField.Text = ""; typeField.Text = ""; domainField.Text = ""; hostField.Text = ""; portField.Text = ""; serviceTextField.Items.Clear(); try { browser = DNSService.Browse(0, 0, typeBox.SelectedItem.ToString(), null, new DNSService.BrowseReply(OnBrowseReply)); } catch { MessageBox.Show("Browse Failed", "Error"); Application.Exit(); } }
private void Form1_Load(object sender, EventArgs e) { IPEndPoint localEP = new IPEndPoint(System.Net.IPAddress.Any, 0); // // create the socket and bind to INADDR_ANY // socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); socket.Bind(localEP); localEP = (IPEndPoint)socket.LocalEndPoint; // // start asynchronous read // SocketStateObject so = new SocketStateObject(socket); socket.BeginReceive(so.m_buffer, 0, SocketStateObject.BUFFER_SIZE, 0, new AsyncCallback(this.OnReadSocket), so); try { // // start the register and browse operations // registrar = DNSService.Register(0, 0, System.Environment.UserName, "_p2pchat._udp", null, null, localEP.Port, null, new DNSService.RegisterReply(OnRegisterReply)); browser = DNSService.Browse(0, 0, "_p2pchat._udp", null, new DNSService.BrowseReply(OnBrowseReply)); } catch { MessageBox.Show("DNSServices Not Available", "Error"); Application.Exit(); } }
private void GetWindowsNetworkConnection() { var dnsSrv = new DNSService(); byte priority = 1; var networkCollection = NetworkListManager.GetNetworks(NetworkConnectivityLevels.All); foreach (var network in networkCollection) { var netAdapter = new NetworkAdapter { Name = network.Name, AdapterId = network.NetworkId, IsConnected = network.IsConnectedToInternet }; cmbNetworkConnection.Items.Add(network.Name); if (network.IsConnected && network.IsConnectedToInternet) { netAdapter.ConnectionCollection = network.Connections; netAdapter.Description = dnsSrv.Current(network.Connections).Description; netAdapter.DnsAddress = dnsSrv.Get(network.Connections); netAdapter.Priority = priority; priority++; } _networkAdapters.Add(netAdapter); } _connectedNetwork = _networkAdapters.SingleOrDefault(s => s.Priority == 1); SetCurrentDNSIPs(_connectedNetwork.DnsAddress); SetConnectionImage(); }
public void CalculateDataBankLocation_Test(double x, double y, double z, double vel) { //Arrange var _dnsService = new DNSService(); //Act var result = _dnsService.CalculateDataBankLocation(x, y, z, vel).Result; //Assert Assert.Equal(1389.57, result); }
// // called when peer target changes // /// <summary> /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e) { PeerData peer = (PeerData)comboBox1.SelectedItem; try { resolver = DNSService.Resolve(0, 0, peer.Name, peer.Type, peer.Domain, new DNSService.ResolveReply(OnResolveReply)); } catch { MessageBox.Show("Unable to Resolve service", "Error"); Application.Exit(); } }
public static IAddress[] StringToAddresses(string str) { var remoteAddresses = new List <IAddress>(); foreach (var remoteAddress in str.Split(',')) { DNSService dns; DHCPService dhcp; WINSService wins; LocalSubnet localSubnet; DefaultGateway defaultGateway; IPRange range; SingleIP ip; NetworkAddress network; if (DNSService.TryParse(remoteAddress, out dns)) { remoteAddresses.Add(dns); } else if (DHCPService.TryParse(remoteAddress, out dhcp)) { remoteAddresses.Add(dhcp); } else if (WINSService.TryParse(remoteAddress, out wins)) { remoteAddresses.Add(wins); } else if (LocalSubnet.TryParse(remoteAddress, out localSubnet)) { remoteAddresses.Add(localSubnet); } else if (DefaultGateway.TryParse(remoteAddress, out defaultGateway)) { remoteAddresses.Add(defaultGateway); } else if (IPRange.TryParse(remoteAddress, out range)) { remoteAddresses.Add(range); } else if (SingleIP.TryParse(remoteAddress, out ip)) { remoteAddresses.Add(ip); } else if (NetworkAddress.TryParse(remoteAddress, out network)) { remoteAddresses.Add(network); } } return(remoteAddresses.ToArray()); }
// ReSharper disable once ExcessiveIndentation public static IAddress[] StringToAddresses(string str) { var remoteAddresses = new List <IAddress>(); foreach (var remoteAddress in str.Split(',')) { if (DNSService.TryParse(remoteAddress, out var dns)) { remoteAddresses.Add(dns); } else if (DHCPService.TryParse(remoteAddress, out var dhcp)) { remoteAddresses.Add(dhcp); } else if (WINSService.TryParse(remoteAddress, out var wins)) { remoteAddresses.Add(wins); } else if (LocalSubnet.TryParse(remoteAddress, out var localSubnet)) { remoteAddresses.Add(localSubnet); } else if (DefaultGateway.TryParse(remoteAddress, out var defaultGateway)) { remoteAddresses.Add(defaultGateway); } else if (IPRange.TryParse(remoteAddress, out var range)) { remoteAddresses.Add(range); } else if (SingleIP.TryParse(remoteAddress, out SingleIP ip)) { remoteAddresses.Add(ip); } else if (NetworkAddress.TryParse(remoteAddress, out var network)) { remoteAddresses.Add(network); } } return(remoteAddresses.ToArray()); }
public void RegisterPeer(string sHostName, string sService) { lock (this) { try { // just register as a peer DataRow newRow = mainService.tblPeers.NewRow(); newRow["Name"] = sHostName; newRow["IP Address"] = DNSService.GetIPAddress(sHostName); newRow["Service"] = sService; newRow["Connected On"] = DateTime.Now; mainService.tblPeers.Rows.Add(newRow); } catch (Exception exp) { Console.WriteLine(exp); } } }
OnResolveService ( ResolveData data ) { resolver.Dispose(); PeerData peer = (PeerData)comboBox1.SelectedItem; peer.Port = data.Port; try { resolver = DNSService.QueryRecord(0, 0, data.HostName, /* ns_t_a */ 1, /* ns_t_c */ 1, new DNSService.QueryRecordReply(OnQueryRecordReply)); } catch { MessageBox.Show("QueryRecord Failed", "Error"); Application.Exit(); } }
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { if (resolver != null) { resolver.Dispose(); } if (browseList.SelectedItem != null) { try { BrowseData data = (BrowseData)browseList.SelectedItem; resolver = DNSService.Resolve(0, 0, data.Name, data.Type, data.Domain, new DNSService.ResolveReply(OnResolveReply)); } catch { MessageBox.Show("Resolve Failed", "Error"); Application.Exit(); } } }
private void BtnAction_Click(object sender, EventArgs e) { if (_connectedNetwork == null) { MyMessageBox.Show(this, Resources.NoConnection, Resources.Attention, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var ips = GetDNSIPs(); var returnValue = new DNSService().Set(_connectedNetwork.Description, ips); switch (returnValue) { case NetworkAdapterConfigurationReturnValue.SuccessfulCompletionNoRebootRequired: SetCurrentDNSIPs(new DNSService().Get(_connectedNetwork.ConnectionCollection)); //ChangeEnable(false); break; default: MyMessageBox.Show(this, Resources.ResourceManager.GetString(returnValue.ToString("g")), Resources.Attention, MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } }
/// <summary> /// Determines whether a string is a valid DNS service /// </summary> /// <returns> /// <see langword="true" /> if <paramref name="str" /> is a valid DNS service; otherwise, <see langword="false" />. /// </returns> /// <param name="str">The string to validate.</param> /// <param name="service">The <see cref="DNSService" /> instance that represents the passed string.</param> public static bool TryParse(string str, out DNSService service) { return(TryParse <DNSService>(str, out service)); }
public DNSController(DNSService dnsService) { _dnsService = dnsService; }