4AspNet IPInfo v1.0

IPInfo.GetInfoByHostAddress Method (String)

Retrieves country information by an IP address or a host name.

public CountryInfo GetInfoByHostAddress(
   string address
);

Parameters

address
The string representation of an IP address or a host name.

Return Value

The CountryInfo structure.

Remarks

Use this overloaded version of GetInfoByHostAddress method when you need to specify an IP address in a string format or you need to get country information by a host name.

You are free to provide argument either like "193.232.248.2" or like "www.4-asp.net". In both cases method first try to determine whether specified argument is an IP address (first case) or a host name (second case). In first case method simply returns CountryInfo for specified address. In second case the IP address is retrieved using DNS-query and then this address is used to get CountryInfo structure.

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.

Exceptions

Exception TypeCondition
ArgumentNullExceptionThrown when specified argument is a null reference (Nothing in Visual Basic).
CountryInfoNotFoundExceptionThrown when property ThrowIfNotFound is set to true and there is no country information for a specified address.
SocketExceptionThrown when host name is specified as an argument but DNS server could not be contacted or IP address cannot be found.

Example

For an example see IPInfo overview.

See Also

IPInfo Class | ForAspNet.IPInfo Namespace | IPInfo.GetInfoByHostAddress Overload List