com.jeffpalm.logfiles
Class NetGeoClient

java.lang.Object
  extended by com.jeffpalm.logfiles.NetGeoClient

public class NetGeoClient
extends java.lang.Object


Field Summary
static int ARRAY_LENGTH_LIMIT
           
static java.lang.String CITY_GRAN
           
static java.lang.String COUNTRY_GRAN
           
static boolean DEBUG
           
static java.lang.String DEFAULT_SERVER_URL
           
static int DEFAULT_TIMEOUT
           
static java.lang.String HTTP_ERROR
           
static java.lang.String INPUT_ERROR
           
static int LAT_INDEX
           
static int LONG_INDEX
           
static java.lang.String LOOKUP_IN_PROGRESS
           
static java.lang.String NETGEO_LIMIT_EXCEEDED
           
static java.lang.String NO_COUNTRY
           
static java.lang.String NO_MATCH
           
static java.lang.String OK
           
static java.lang.String STATE_GRAN
           
static java.lang.String UNKNOWN
           
static java.lang.String VERSION
           
static java.lang.String WHOIS_ERROR
           
static java.lang.String WHOIS_TIMEOUT
           
 
Constructor Summary
NetGeoClient()
          Description: NetGeoClient constructor
NetGeoClient(java.lang.String applicationName)
          Description: NetGeoClient constructor
NetGeoClient(java.lang.String applicationName, java.lang.String netGeoUrl)
          Description: NetGeoClient constructor
 
Method Summary
 void clearCache()
           
 void clearLocalCache()
          Description: Remove all entries from the local cache.
 void clearLocalCacheEntry(java.lang.String target)
          Description: Remove the entry in the local cache with a key matching the standardized form of the input target.
static float[] convertLatLong(java.util.Hashtable latLongHash)
          Description: Convert the Hashtable returned by getLatLong into a 2-element float array.
 java.lang.String getCountry(java.lang.String target)
          Description: Returns the country corresponding to the input target string, or returns NO_MATCH or NO_COUNTRY.
 java.util.Hashtable[] getCountryArray(java.lang.String[] stringArray)
          Description:
static float getLat(java.util.Hashtable latLongHash)
          Description: Extract the latitude string from the lat/long hashtable and return it as a float primitive.
 java.util.Hashtable getLatLong(java.lang.String target)
          Description: Returns a hashtable containing ( String, String ) pairs, with the keys LAT, LONG, LAT_LONG_GRAN, and STATUS.
 java.util.Hashtable[] getLatLongArray(java.lang.String[] stringArray)
          Description:
static float getLong(java.util.Hashtable latLongHash)
          Description: Extract the longitude string from the lat/long hashtable and return it as a float primitive.
 java.util.Hashtable getRecord(java.lang.String target)
          Description: Returns a full record for the input target string.
 java.util.Hashtable[] getRecordArray(java.lang.String[] stringArray)
          Description:
 boolean getSave()
           
static java.lang.String[] intArrayToStringArray(int[] intArray)
          Description: Convert an int array to an equivalent String array.
 void load()
          jpalm
static void main(java.lang.String[] argv)
          Description:
 void save()
          jpalm
 void setNonblocking(boolean trueOrFalse)
          Description: Specify whether or not the server should wait on whois lookups.
 void setSave(boolean save)
           
 void setTimeout(int seconds)
          Description: Set the time limit (in seconds) to be allowed for a whois lookup.
 java.lang.String updateCountryArray(java.util.Hashtable[] recordArray)
          Description:
 java.lang.String updateLatLongArray(java.util.Hashtable[] recordArray)
          Description:
 java.lang.String updateRecordArray(java.util.Hashtable[] recordArray)
          Description:
 void useLocalCache(boolean trueOrFalse)
          Description: Keep a cache of results in memory on the machine executing this NetGeoClient code.
 java.lang.String verifyAsNumberFormat(java.lang.String methodName, java.lang.String input)
          Description:
 boolean verifyDomainNameFormat(java.lang.String input, int lastDotIndex)
          Description:
 void verifyInputFormat(java.lang.String methodName, java.util.Hashtable hashtable)
          Description: Test the target string from the input hashtable and make sure it's in an acceptable format.
 boolean verifyIpAddressFormat(java.lang.String input, int lastDotIndex)
          Description:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
See Also:
Constant Field Values

DEFAULT_SERVER_URL

public static final java.lang.String DEFAULT_SERVER_URL
See Also:
Constant Field Values

OK

public static final java.lang.String OK
See Also:
Constant Field Values

LOOKUP_IN_PROGRESS

public static final java.lang.String LOOKUP_IN_PROGRESS
See Also:
Constant Field Values

NO_MATCH

public static final java.lang.String NO_MATCH
See Also:
Constant Field Values

NO_COUNTRY

public static final java.lang.String NO_COUNTRY
See Also:
Constant Field Values

UNKNOWN

public static final java.lang.String UNKNOWN
See Also:
Constant Field Values

WHOIS_ERROR

public static final java.lang.String WHOIS_ERROR
See Also:
Constant Field Values

HTTP_ERROR

public static final java.lang.String HTTP_ERROR
See Also:
Constant Field Values

INPUT_ERROR

public static final java.lang.String INPUT_ERROR
See Also:
Constant Field Values

WHOIS_TIMEOUT

public static final java.lang.String WHOIS_TIMEOUT
See Also:
Constant Field Values

NETGEO_LIMIT_EXCEEDED

public static final java.lang.String NETGEO_LIMIT_EXCEEDED
See Also:
Constant Field Values

ARRAY_LENGTH_LIMIT

public static final int ARRAY_LENGTH_LIMIT
See Also:
Constant Field Values

CITY_GRAN

public static final java.lang.String CITY_GRAN
See Also:
Constant Field Values

STATE_GRAN

public static final java.lang.String STATE_GRAN
See Also:
Constant Field Values

COUNTRY_GRAN

public static final java.lang.String COUNTRY_GRAN
See Also:
Constant Field Values

DEFAULT_TIMEOUT

public static final int DEFAULT_TIMEOUT
See Also:
Constant Field Values

LAT_INDEX

public static final int LAT_INDEX
See Also:
Constant Field Values

LONG_INDEX

public static final int LONG_INDEX
See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values
Constructor Detail

NetGeoClient

public NetGeoClient(java.lang.String applicationName)
Description: NetGeoClient constructor

Parameters:
String - - application name and version, e.g., "plot_AS_loc/1.2.3".

NetGeoClient

public NetGeoClient()
Description: NetGeoClient constructor

Parameters:
-

NetGeoClient

public NetGeoClient(java.lang.String applicationName,
                    java.lang.String netGeoUrl)
Description: NetGeoClient constructor

Parameters:
String - - application name and version, e.g., "plot_AS_loc/1.2.3".
String - - url of NetGeo server, e.g., http://www.caida.org/cgi-bin/netgeo/netgeo.cgi
Method Detail

main

public static void main(java.lang.String[] argv)
Description:

Parameters:
String[] - argv

setTimeout

public void setTimeout(int seconds)
Description: Set the time limit (in seconds) to be allowed for a whois lookup. The default value is DEFAULT_TIMEOUT. For the client, this timeout is advisory only and may be overridden by the server.

Parameters:
int - - seconds

setNonblocking

public void setNonblocking(boolean trueOrFalse)
Description: Specify whether or not the server should wait on whois lookups. A value of true for nonblocking means that the server will not wait on whois lookups, if the target is not found in the NetGeo database the server will return immediately. The default is nonblocking = false, i.e., the server will wait on whois lookups if needed.

Parameters:
boolean - - trueOrFalse

useLocalCache

public void useLocalCache(boolean trueOrFalse)
Description: Keep a cache of results in memory on the machine executing this NetGeoClient code. Default is true, i.e., by default a local cache will be used. useLocalCache( false ) turns off the local caching.

Parameters:
boolean - - trueOrFalse

clearLocalCache

public void clearLocalCache()
Description: Remove all entries from the local cache.


clearLocalCacheEntry

public void clearLocalCacheEntry(java.lang.String target)
Description: Remove the entry in the local cache with a key matching the standardized form of the input target. This method does nothing if the specified target is not found in the cache.

Parameters:
String - - target

setSave

public final void setSave(boolean save)

getSave

public final boolean getSave()

save

public void save()
jpalm


load

public void load()
jpalm


clearCache

public void clearCache()

getRecord

public java.util.Hashtable getRecord(java.lang.String target)
Description: Returns a full record for the input target string.

Parameters:
String -
Returns:
Hashtable

getCountry

public java.lang.String getCountry(java.lang.String target)
Description: Returns the country corresponding to the input target string, or returns NO_MATCH or NO_COUNTRY.

Parameters:
String -
Returns:
String

getLatLong

public java.util.Hashtable getLatLong(java.lang.String target)
Description: Returns a hashtable containing ( String, String ) pairs, with the keys LAT, LONG, LAT_LONG_GRAN, and STATUS.

Parameters:
String -
Returns:
Hashtable

getRecordArray

public java.util.Hashtable[] getRecordArray(java.lang.String[] stringArray)
Description:

Parameters:
String[] -
Returns:
Hashtable[]

getCountryArray

public java.util.Hashtable[] getCountryArray(java.lang.String[] stringArray)
Description:

Parameters:
String[] -
Returns:
Hashtable[]

getLatLongArray

public java.util.Hashtable[] getLatLongArray(java.lang.String[] stringArray)
Description:

Parameters:
String[] -
Returns:
Hashtable[]

updateRecordArray

public java.lang.String updateRecordArray(java.util.Hashtable[] recordArray)
Description:

Parameters:
Hashtable[] -
Returns:
String

updateCountryArray

public java.lang.String updateCountryArray(java.util.Hashtable[] recordArray)
Description:

Parameters:
Hashtable[] -
Returns:
String

updateLatLongArray

public java.lang.String updateLatLongArray(java.util.Hashtable[] recordArray)
Description:

Parameters:
Hashtable[] -
Returns:
String

intArrayToStringArray

public static java.lang.String[] intArrayToStringArray(int[] intArray)
Description: Convert an int array to an equivalent String array. This can be used to convert an array of AS numbers represented as ints to the type required for input into getRecordArray, getCountryArray, etc.

Parameters:
int[] -
Returns:
String[]

getLat

public static float getLat(java.util.Hashtable latLongHash)
Description: Extract the latitude string from the lat/long hashtable and return it as a float primitive.

Parameters:
Hashtable -
Returns:
float

getLong

public static float getLong(java.util.Hashtable latLongHash)
Description: Extract the longitude string from the lat/long hashtable and return it as a float primitive.

Parameters:
Hashtable -
Returns:
float

convertLatLong

public static float[] convertLatLong(java.util.Hashtable latLongHash)
Description: Convert the Hashtable returned by getLatLong into a 2-element float array.

Parameters:
Hashtable - - latLongHash
Returns:
float[]

verifyInputFormat

public void verifyInputFormat(java.lang.String methodName,
                              java.util.Hashtable hashtable)
Description: Test the target string from the input hashtable and make sure it's in an acceptable format. The input can be an AS number string (with or without a leading "AS"), an IP address in dotted decimal format, or a domain name. Stores the standardized target into the hashtable if input is in an acceptable format, otherwise stores null into table.

Parameters:
String - - methodName
Hashtable - - hashtable

verifyAsNumberFormat

public java.lang.String verifyAsNumberFormat(java.lang.String methodName,
                                             java.lang.String input)
Description:

Parameters:
String - - methodName
String - - input, already trimmed and not null
Returns:
String

verifyDomainNameFormat

public boolean verifyDomainNameFormat(java.lang.String input,
                                      int lastDotIndex)
Description:

Parameters:
String - - input, already trimmed and not null
int - - lastDotIndex
Returns:
String

verifyIpAddressFormat

public boolean verifyIpAddressFormat(java.lang.String input,
                                     int lastDotIndex)
Description:

Parameters:
String - - input, already trimmed and not null
int - - lastDotIndex
String - - lastOctet, the part of the input string following the last dot. In an IP address this is the 4th octet.
Returns:
String