(ip)
Get geographic coordinates from IP using geoip database
Get geographic coordinates from IP using geoip database
Get geographic coordinates from IP using geoip database
def locate_ip(ip):
    """Get geographic coordinates from IP using geoip database"""
    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)
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 )