Retrieves country information by an IP address.
The CountryInfo structure.
Use this overloaded version of GetInfoByHostAddress method when you need to specify an IPAddress object as an argument.
When country information for the specified address is absent and ThrowIfNotFound property is set to false method will return CountryInfo structure without significant information. If ThrowIfNotFound is set to true, the exception of type CountryInfoNotFoundException will be thrown.
| Exception Type | Condition |
|---|---|
| ArgumentNullException | Thrown when specified argument is a null reference (Nothing in Visual Basic). |
| CountryInfoNotFoundException | Thrown when property ThrowIfNotFound is set to true and there is no country information for a specified address. |
The following example demonstrates using of GetInfoByHostAddress specifying the IPAddress object as an argument.
using System;
using System.Net;
using ForAspNet.IPInfo;
namespace Test
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
License.LicenseKey = "<put license string here>";
CountryInfo[] infos = GetMultipleInfoForHostName("www.microsoft.com");
}
static CountryInfo[] GetMultipleInfoForHostName(string hostName)
{
// get server related information.
IPHostEntry heserver = Dns.Resolve(hostName);
// creating an array of CountryInfo structures with size enough to hold
// information for all resolved IP entries
CountryInfo[] ret = new CountryInfo[heserver.AddressList.Length];
// initializing a new instance of IPInfo
IPInfo ipi = new IPInfo();
// iterate through address list and retrieve country information for each entry
for(int i=0; i<heserver.AddressList.Length; i++)
ret[i] = ipi.GetInfoByHostAddress(heserver.AddressList[i]);
return ret;
}
}
}
IPInfo Class | ForAspNet.IPInfo Namespace | IPInfo.GetInfoByHostAddress Overload List