StringIPToLong Method

This method is converts an IP address from its string format to a four-byte long integer.

Syntax:

 IPasLong = chObj.StringIPToLong [ipAsStringToConvert]

ipAsStringToConvert: Optional. If omitted, the IP address for the currently initialized CountryHawk object is returned as a long integer. Otherwise the specified IP address is converted and returned as a long integer.

Returns:

A four-byte long integer in the range of -2147483648 to 2147483647.

Example:

<% set chObj = CreateObject("cyScape.countryObj")

yourIPAsLong = chObj.StringIPToLong

response.write "Your IP as a string is: " & chObj.IPAddr

response.write "<p> Your IP as a long integer is: " & yourIPAsLong %>

specificIPAsLong = chObj.StringIPToLong "207.46.230.220"

response.write "<p> 207.46.230.220 as a long is : " & specificIPAsLong %>

 

This conversion is handy for storing IP addresses in the most efficient format. For example, it typically takes 12-15 characters in a database to store an IP address as a string. Yet it only takes 4 bytes to store it as a long integer. That's a savings of about 10 bytes (about 70%) per database record. If you are storing 5,000,000 IPs in your database, that would be a savings in disk space of about 50MB. In addition, it is faster and more efficient for your database to work with integers than strings.

Use the LongToStringIP method to later change this converted value back from a long to its IP address string format.

 

See Also:

LongToStringIP Method

CountryStats Object Properties and Methods

RegionStats Object Properties and Methods