@conf.commands.register
def locate_ip(ip):
 ip = map(int, ip.split('.'))
 ip = (((ip[3] + (ip[2] << 8L)) + (ip[1] << 16L)) + (ip[0] << 24L))
 cloc = country_loc_kdb.get_base()
 db = IP_country_kdb.get_base()
 d = 0
 f = (len(db) - 1)
 while ((f - d) > 1):
  guess = ((d + f) / 2)
  if (ip > db[guess][0]):
   d = guess
  else:
   f = guess
 (s, e, c) = db[guess]
 if ((s <= ip) and (ip <= e)):
  return cloc.get(c, None)

@ conf . commands . register def locate_ip ( ip ) : ip = map ( int , ip . split ( '.' ) ) ip = ( ( ( ip [ 3 ] + ( ip [ 2 ] << 8 L ) ) + ( ip [ 1 ] << 16 L ) ) + ( ip [ 0 ] << 24 L ) ) cloc = country_loc_kdb . get_base ( ) db = IP_country_kdb . get_base ( ) d = 0 f = ( len ( db ) - 1 ) while ( ( f - d ) > 1 ) : guess = ( ( d + f ) / 2 ) if ( ip > db [ guess ] [ 0 ] ) : d = guess else : f = guess ( s , e , c ) = db [ guess ] if ( ( s <= ip ) and ( ip <= e ) ) : return cloc . get ( c , None )
get geographic coordinates from ip using geoip database .