i'm writing a script that resolve ip address for domain using C#
the problem is that i have a lot of domains that does not resolve to an IP, so the code (Dns.GetHostAddresses
) is running for a long time trying to resolve an IP for a domain that doesn't have an IP.
this is the code:
public string getIPfromHost(string host)
{
try
{
var domain = Dns.GetHostAddresses(host)[0];
return domain.ToString();
}
catch (Exception)
{
return "No IP";
}
}
what i want to do is if there is no IP after 1 sec i want to return "No IP"
how can i achieve that?