C# .NET - How to get match domain name to ip address
Asked By Erik Little on 17-Aug-06 12:10 AM
Hi...
Can somone point me in the ritght direction on how to obtain match a ip address to a domain..?
I would like to match a domain name to the ip address that i have here locally.. How is this done?? I can navigate directories when i type the ip like 143.165.0.23. How do i mask this with a name?
thanks
erik
System Dns GetHostByAddress
Asked By mv ark on 17-Aug-06 12:39 AM
gets DNS host information for an IP address. Try this snippet from MSDN.
string IpAddressString = "208.5.42.49"; //eggheadcafe
try
{
IPAddress hostIPAddress = IPAddress.Parse(IpAddressString);
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
// Get the IP address list that resolves to the host names contained in
// the Alias property.
IPAddress[] address = hostInfo.AddressList;
// Get the alias names of the addresses in the IP address list.
String[] alias = hostInfo.Aliases;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nAliases :");
for(int index=0; index < alias.Length; index++) {
Console.WriteLine(alias[index]);
}
Console.WriteLine("\nIP address list : ");
for(int index=0; index < address.Length; index++) {
Console.WriteLine(address[index]);
}
}
catch(SocketException e)
{
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(FormatException e)
{
Console.WriteLine("FormatException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
catch(Exception e)
{
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
}
thanks
Asked By Erik Little on 17-Aug-06 01:05 AM
orien redt replied to Erik Little on 02-Feb-11 02:26 AM
For this match domain to ip address i have gone for http:// There it provides ip to domain, ping, DNS query etc.,From that i get a clear idea about it.