Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 426

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/templates/ja_purity/ja_templatetools.php on line 49
DNS Lookup in C# - The Scripts Library Community

Free Programming Tutorials & Source Code

 
  • Increase font size
  • Default font size
  • Decrease font size
Home C# DNS Lookup in C#

DNS Lookup in C#

E-mail
(2 votes, average: 3.50 out of 5)
The following sample will show you how to get DNS for a particular hostname. It uses the System.Net namespace.

Add the following controls to your form:
TextBox. Name it as txtHostName
Button. Name it as btnDNSLookup

dns Lookup

Switch to the View Code mode. Add the System.Net namespace at the top of your document:

using System.Net;

Then add the DNSLookup function:

       string DNSLookup(IPHostEntry iphe)
          {
              String str;
              str = "";

              str += "Host Name:\n" + iphe.HostName;
              str += "\n\nAliases:\n";
              foreach (string alias in iphe.Aliases)
            {
                str += alias + "\n";
            }

            str +="\nAddresses:" ;
            foreach (IPAddress address in iphe.AddressList)
            {
                str += "\n"+ address.ToString();
            }
         
            return str;
        }

Then the btnDNSLookup Click Event:

        private void btnDNSLookup_Click(object sender, EventArgs e)
        {
            try
            {
                IPHostEntry iphe = Dns.GetHostByName(this.txtHostName.Text);
                MessageBox.Show(DNSLookup(iphe));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }


You may also see DNS Reverse lookup in C#

That’s it!