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

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!




