コード例 #1
0
ファイル: Program.cs プロジェクト: CuneytKukrer/TestProject
        private static StringBuilder LookupHost(string[] hostNameOrAddresses)
        {

            var stringBuilder = new StringBuilder();
            var Options = new JHSoftware.DnsClient.RequestOptions();
            var servers = new string[] { "ns1.google.com", "ns2.google.com", "ns3.google.com", "ns4.google.com" };
            var serverList = new List<string>()
            {
                "8.8.8.8","8.8.4.4"
            };

            //
            foreach (var s in servers)
            {
                foreach (var ipaddress in System.Net.Dns.GetHostAddresses(s))
                {
                    serverList.Add(ipaddress.ToString());
                }
            }
            //Options.DnsServers = new System.Net.IPAddress[] { 
            //                   System.Net.IPAddress.Parse("8.8.8.8"), 
            //                   System.Net.IPAddress.Parse("8.8.4.4"),
            //                   //System.Net.IPAddress.Parse("216.239.32.10")
            //                };
            Options.DnsServers = serverList.Select(si => System.Net.IPAddress.Parse(si)).ToArray();
            foreach (var hostNameOrAddress in hostNameOrAddresses)
            {
                var IPs = JHSoftware.DnsClient.LookupHost(hostNameOrAddress,
                                                          JHSoftware.DnsClient.IPVersion.IPv4,
                                                          Options);
                if (hostNameOrAddress.Equals("g.cn"))
                {
                    var ipcn = "google_cn = " + string.Join("|", IPs.Select(i => i.ToString()));
                    stringBuilder.AppendLine(ipcn);
                }
                else if (hostNameOrAddress.Equals("google.com.hk"))
                {
                    var iphk = "google_hk = " + string.Join("|", IPs.Select(i => i.ToString()));
                    stringBuilder.AppendLine(iphk);
                }

                //foreach (var IP in IPs)
                //{
                //   // Console.WriteLine(IP.ToString());
                //}
            }
            return stringBuilder;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: rajeshwarn/TestProject
        private static StringBuilder LookupHost(string[] hostNameOrAddresses)
        {
            var stringBuilder = new StringBuilder();
            var Options       = new JHSoftware.DnsClient.RequestOptions();
            var servers       = new string[] { "ns1.google.com", "ns2.google.com", "ns3.google.com", "ns4.google.com" };
            var serverList    = new List <string>()
            {
                "8.8.8.8", "8.8.4.4"
            };

            //
            foreach (var s in servers)
            {
                foreach (var ipaddress in System.Net.Dns.GetHostAddresses(s))
                {
                    serverList.Add(ipaddress.ToString());
                }
            }
            //Options.DnsServers = new System.Net.IPAddress[] {
            //                   System.Net.IPAddress.Parse("8.8.8.8"),
            //                   System.Net.IPAddress.Parse("8.8.4.4"),
            //                   //System.Net.IPAddress.Parse("216.239.32.10")
            //                };
            Options.DnsServers = serverList.Select(si => System.Net.IPAddress.Parse(si)).ToArray();
            foreach (var hostNameOrAddress in hostNameOrAddresses)
            {
                var IPs = JHSoftware.DnsClient.LookupHost(hostNameOrAddress,
                                                          JHSoftware.DnsClient.IPVersion.IPv4,
                                                          Options);
                if (hostNameOrAddress.Equals("g.cn"))
                {
                    var ipcn = "google_cn = " + string.Join("|", IPs.Select(i => i.ToString()));
                    stringBuilder.AppendLine(ipcn);
                }
                else if (hostNameOrAddress.Equals("google.com.hk"))
                {
                    var iphk = "google_hk = " + string.Join("|", IPs.Select(i => i.ToString()));
                    stringBuilder.AppendLine(iphk);
                }

                //foreach (var IP in IPs)
                //{
                //   // Console.WriteLine(IP.ToString());
                //}
            }
            return(stringBuilder);
        }
コード例 #3
0
 public void ThreadFunction()
 {
     while (pos < count)
     {
         if (pos % 1000 == 0) Console.WriteLine(pos);
         string tdns = dns[pos++];
         if (tdns.Contains(":")) continue;
         try
         {
             JHSoftware.DnsClient.RequestOptions opt = new JHSoftware.DnsClient.RequestOptions();
             opt.DnsServers = new IPAddress[] { IPAddress.Parse(tdns) };
             IPAddress[] ips = JHSoftware.DnsClient.LookupHost(domain, JHSoftware.DnsClient.IPVersion.IPv4, opt);
             foreach (IPAddress ip in ips)
             {
                 res.Add(ip.ToString());
             }
         }
         catch (Exception ex)
         {
             //Console.WriteLine(ex.ToString());
         }
     }
 }
コード例 #4
0
ファイル: GetIpAddress.cs プロジェクト: GeorgeChe/SD-Tool
        private string getIPfromspecificDCs(string tagno, int DCno)
        {
            string toReturn = string.Empty;
            try
            {
                var Options = new JHSoftware.DnsClient.RequestOptions();
                Options.DnsServers = new IPAddress[] {IPAddress.Parse(DC_IPs[DCno, 1])};
                var IPs = JHSoftware.DnsClient.LookupHost(tagno + ".sch.com",JHSoftware.DnsClient.IPVersion.IPv4, Options);
                int i = 0;
                foreach (var IP in IPs)
                {
                    Ping pingSender = new Ping();
                    IPAddress address = IP;
                    PingReply reply = pingSender.Send(address, 200);
                    string pingreply = "NO";
                    if (reply.Status == IPStatus.Success)
                        pingreply = "YES";
                    if (DC_IPs[DCno, 0].Length < 9)
                        i = 30;
                    else
                        i = 21;
                    toReturn += String.Format("{0} {1} {2} \n", DC_IPs[DCno, 0].PadRight(i), IP.ToString().PadRight(40) ,pingreply.PadRight(60));
                }
            }
            catch (JHSoftware.DnsClient.NoDefinitiveAnswerException exceptie)
            {
                MessageBox.Show(exceptie.Message);
                for (int i = 0; i < exceptie.ServerProblems.Count; i++)
                    MessageBox.Show(exceptie.ServerProblems[i].ProblemDescription);
            }
            catch (JHSoftware.DnsClient.NXDomainException exceptie)
            {
                MessageBox.Show(exceptie.Message);
            }

            return toReturn;
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: napalm255/dnsmonitor
        public void queryDNS()
        {
            // Refresh Config
            loadDNSConfig();

            // Clear Panels
            this.Controls["Main"].Controls.Clear();
            try
            {
                foreach (string dom in dnsDomains)
                {
                    if (dom == "") break;
                    List<string> ipResults = new List<string>();
                    foreach (string srv in dnsServers)
                    {
                        var Options = new JHSoftware.DnsClient.RequestOptions();
                        Options.RetryCount = 1;
                        Options.TimeOut = new TimeSpan(0, 0, 1);
                        Options.DnsServers = new System.Net.IPAddress[] { System.Net.IPAddress.Parse(srv.Trim()) };
                        try
                        {
                            var IPs = JHSoftware.DnsClient.LookupHost(dom.Trim(), JHSoftware.DnsClient.IPVersion.IPv4, Options);
                            foreach (var IP in IPs)
                            {
                                ipResults.Add(IP.ToString());
                            }
                        }
                        catch (Exception e)
                        {
                            //ipResults.Add(e.ToString());
                        }
                    }

                    string matchedLocation = "";
                    string matchedIP = "";
                    int mismatchCount = 0;
                    int matchCount = 0;
                    var uniqueIPs = new HashSet<string>(ipResults);
                    int ipCount = ipResults.Count;
                    foreach (string s in ipResults)
                    {
                        matchedIP = s;
                        foreach (KeyValuePair<string, List<string>> match in dnsMatches)
                        {
                            if (match.Value.Contains(matchedIP))
                            {
                                matchedLocation = match.Key;
                                matchCount++;
                            }
                            else
                            {
                                mismatchCount++;
                            }
                        }
                    }

                    Match matchKeyVal = Regex.Match(matchedLocation, @"^(.*)\:(.*)$");
                    string matchStats = "(" + matchCount + "/" + ipCount + ")";
                    string matchLocation = matchKeyVal.Groups[1].Value;
                    string matchColor = matchKeyVal.Groups[2].Value;

                    addPanel(matchLocation, matchStats, dom, matchedIP, ipResults, matchColor);
                }
            }
            catch
            {
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: fararoni/DNSPing
        public Registro resolve(String dns, String registro)
        {
            Registro r = new Registro();
            r.NameServer = dns;
            r.Record = registro;
            r.IpNameServer = "?.?.?.?";
            //1.- Resolver la IP del Servidor de DNS
            try
            {
                IPAddress address = IPAddress.Parse(r.NameServer);
                r.IpNameServer = r.NameServer;
                r.NameServer = "";
            }
            catch (Exception)
            {
                ////--- Nada que hacer
            }

            if ("?.?.?.?".Equals(r.IpNameServer))
            {
                try
                {
                    r.FechaHora = string.Format("{0}", DateTime.Now);
                    var IPs = JHSoftware.DnsClient.LookupHost(dns, JHSoftware.DnsClient.IPVersion.IPv4, OptionsDns);
                    foreach (var IP in IPs)
                    {
                        r.IpNameServer = IP.ToString();
                        break;
                    }
                }
                catch (DnsClient.NoDefinitiveAnswerException ndef)
                {
                    foreach (JHSoftware.DnsClient.NoDefinitiveAnswerException.ServerProblem sp in ndef.ServerProblems)
                        r.MensajeError.Append(string.Format("NS+ {0}", sp.ProblemDescription));
                    return r;
                }
                catch (Exception e)
                {
                    r.MensajeError.Append(string.Format("NS- {0}", e.Message));
                    return r;
                }
            }
            //2.- Resolver la IP del RegistroDnsBuscado
            DateTime start = DateTime.Now;
            r.FechaHora = string.Format("{0}", start);
            try
            {

                var Options = new JHSoftware.DnsClient.RequestOptions();
                Options.DnsServers = new System.Net.IPAddress[] { System.Net.IPAddress.Parse(r.IpNameServer) };
                var Response = JHSoftware.DnsClient.Lookup(r.Record, JHSoftware.DnsClient.RecordType.A, Options);
                TimeSpan timeDiff = DateTime.Now - start;

                r.IpNameServer = string.Format("{0}", Response.FromServer);
                r.TiempoResolucion = string.Format("{0,7:0.00}", timeDiff.TotalMilliseconds);
                r.Autoritativo = (Response.AuthoritativeAnswer ? "Autoritativa" : "No Autoritativa");
                r.Recursivo = (Response.RecursionAvailable ? "Recursivo" : "No Recursivo");

                foreach (var Record in Response.AnswerRecords)
                {
                    r.RegistroA.Append(string.Format("{0} {1} {2,3} {3,15}",
                                            Record.Name,
                                            Record.Type.ToString(),
                                            Record.TTL,
                                            Record.Data));
                }

            }
            catch (DnsClient.NoDefinitiveAnswerException ndef)
            {
                TimeSpan timeDiff = DateTime.Now - start;
                r.TiempoResolucion = string.Format("{0,7:0.00}", timeDiff.TotalMilliseconds);
                foreach (JHSoftware.DnsClient.NoDefinitiveAnswerException.ServerProblem sp in ndef.ServerProblems)
                    r.MensajeError.Append(sp.ProblemDescription);

            }
            catch (DnsClient.NXDomainException ex)
            {
                TimeSpan timeDiff = DateTime.Now - start;
                r.TiempoResolucion = string.Format("{0,7:0.00}", timeDiff.TotalMilliseconds);
                r.MensajeError.Append(ex.Message);

            }
            catch (JHSoftware.DnsClient.NoDataException ex)
            {
                TimeSpan timeDiff = DateTime.Now - start;
                r.TiempoResolucion = string.Format("{0,7:0.00}", timeDiff.TotalMilliseconds);
                r.MensajeError.Append(ex.Message);
            }

            catch (Exception e)
            {
                TimeSpan timeDiff = DateTime.Now - start;
                r.TiempoResolucion = string.Format("{0,7:0.00}", timeDiff.TotalMilliseconds);

                r.MensajeError.Append(e.Message);
            }
            //System.Console.WriteLine(r);
            return r;
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: fararoni/DNSPing
 public ResolveRecord()
 {
     OptionsDns = new JHSoftware.DnsClient.RequestOptions();
     OptionsDns.DnsServers = new System.Net.IPAddress[] { System.Net.IPAddress.Parse("8.8.8.8"), System.Net.IPAddress.Parse("8.8.4.4") };
 }
コード例 #8
0
        private void job(object sender, DoWorkEventArgs e)
        {
            bool   success;
            string ipaddr = "";

            if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
            {
                // Find IPs
                var host = Dns.GetHostEntry(Dns.GetHostName());
                foreach (var ip in host.AddressList)
                {
                    //ipaddr += ip.ToString() + Environment.NewLine;
                }

                // Test Router by tring to connect to the web interface.
                var router = netTestMain.GetDefaultGateway();
                //ipaddr += router.ToString() + Environment.NewLine;
                success = netTestMain.probeTcpPort(router, 1000, 80);
                if (!success)
                {
                    ipaddr  += "Router not responding. Try rebooting the router." + Environment.NewLine;
                    e.Result = ipaddr;
                    return;
                }
                ipaddr += "Router works!" + Environment.NewLine;

                // Test remote site
                var remote = IPAddress.Parse("8.8.8.8");
                //ipaddr += router.ToString() + Environment.NewLine;
                success = netTestMain.probeTcpPort(remote, 1000, 53);
                if (!success)
                {
                    ipaddr  += "Remote site not responding. Try rebooting your modem if you have one. If you don't, maybe your router might be the problem. Otherwise, it seems like your ISP is really down right now." + Environment.NewLine;
                    e.Result = ipaddr;
                    return;
                }
                ipaddr += "Remote site works!" + Environment.NewLine;

                // Test DNS
                try
                {
                    IPAddress[] dns = Dns.GetHostAddresses("google.com");
                }
                catch (SocketException se)
                {
                    ipaddr += "Default DNS didn't resolve." + Environment.NewLine;

                    if (se.SocketErrorCode == SocketError.HostNotFound)
                    {
                        var opts = new JHSoftware.DnsClient.RequestOptions();
                        opts.DnsServers = new IPAddress[] { IPAddress.Parse("8.8.8.8") };
                        try
                        {
                            var ips = JHSoftware.DnsClient.LookupHost("google.com", JHSoftware.DnsClient.IPVersion.IPv4, opts);
                            ipaddr += "Custom DNS did resolve. Your ISP DNS servers appear to be down.  You can wait for them to come back up or you can switch to OpenDNS http://208.69.38.205/";
                        }
                        catch
                        {
                            ipaddr += "Custom DNS didn't resolve.  This is strange.  Try rebooting your computer/router. If it still doesn't work, something fishy is going on - something like a firewall blocking DNS or something." + Environment.NewLine;
                        }
                        e.Result = ipaddr;
                        return;
                    }
                }
                ipaddr += "DNS works!" + Environment.NewLine;
            }
            else
            {
                ipaddr   = "Not connected to a network. If you use WiFi and don't see your usual network, try rebooting your router.  If you use ethernet, make sure you're plugged in and also try rebooting.";
                e.Result = ipaddr;
                return;
            }

            ipaddr += "It looks like everything is working.  I'm not sure what's going on.";

            e.Result = ipaddr;
        }