Function to check the given domain actually exists or not.

Code Snippet

private bool isRealDomain(string hostname)
{      
	bool isReal = false;
	try
	{
		IPHostEntry IPhst = Dns.GetHostEntry(hostname);
		IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
		Socket s = new Socket(endPt.AddressFamily,SocketType.Stream, ProtocolType.Tcp);
		s.Connect(endPt);
		s.Close();
		isReal = true;
	}
	catch (<specific exceptions here>)
	{
		//do something;      
	}
	return isReal; 
}

Sample Usage

isRealDomain("google.com");

Note

using System.Net;
Just a sample. Need to modified depend on requirement.


Reference/Credit

http://stackoverflow.com/questions/1000747/validating-an-email-address-in-c




author's photo

Author : Blue Cloud

Just a normal software developer who love to write code. Developing professional software since 1999. After working in the software industry for many years, I've started my own website to share knowledges and experiences.

COMMENTS
blog comments powered by Disqus