Retrieves country information by a raw format of IP address.
The CountryInfo structure.
Use this overloaded version of GetInfoByHostAddress method when you need to specify raw IP address as an argument.
If the IP address has a form aaa.bbb.ccc.ddd when raw IP address is a number obtained with a next formula:
raw_ip_address = aaa * 16777216L + bbb * 65536L + ccc * 256L + ddd. 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 |
|---|---|
| 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 raw IP address as an argument.
public string GetCountryName(byte[] addressBytes)
{
if(addressBytes.Length != 4)
throw new ArgumentException();
long address = addressBytes[0] * 16777216L + addressBytes[1] * 65536L +
addressBytes[2] * 256L + addressBytes[3];
// assume what license is already initialized
IPInfo ipi = new IPInfo();
CountryInfo ci = ipi.GetInfoByHostAddress(address);
return ci.CountryName;
}
IPInfo Class | ForAspNet.IPInfo Namespace | IPInfo.GetInfoByHostAddress Overload List