DNS query: Difference between revisions

Add C Sharp example
(Ada example restricted to IP v4)
(Add C Sharp example)
Line 81:
return 0;
}</lang>
 
=={{header|C Sharp}}==
Implementation takes a host name string as a parameter, and returns the IP addresses in a comma-delimitd string. Note that a failed lookup throws a SocketException.
<lang csharp>
private string LookupDns(string s)
{
try
{
System.Net.IPHostEntry ip = System.Net.Dns.GetHostEntry(s);
 
string result = ip.AddressList[0].ToString();
 
for (int i = 1; i < ip.AddressList.Length; ++i)
result += ", " + ip.AddressList[i].ToString();
 
return result;
}
catch (System.Net.Sockets.SocketException se)
{
return se.Message;
}
}
</lang>
=={{header|Delphi}}==
The included Indy components wrap GetAddressInfo.
Anonymous user