“Python pygeoip Exemple” Réponses codées

Python pygeoip Exemple

pip install pygeoip
OSP PRO

Python pygeoip Exemple

>>> gi = pygeoip.GeoIP('GeoIPRegion.dat')
>>> gi.region_by_name('apple.com')
{'region_code': 'CA', 'country_code': 'US'}
OSP PRO

Python pygeoip Exemple

>>> gi = pygeoip.GeoIP('GeoIPISP.dat')
>>> gi.isp_by_name('cnn.com')
'Turner Broadcasting System'
OSP PRO

Python pygeoip Exemple

def geo(_file, _ip):
    ''' This function search the geolocation values of an IP address '''
    try:
        _geo = []
        geoDb = pygeoip.GeoIP(_file)
        ip_dictionary_values = geoDb.record_by_addr(_ip)
        ip_list_values = ip_dictionary_values.items()
        for item in ip_list_values:
            _geo.append({item[0]:item[1]})
        return _geo
    except:
        pass 
OSP PRO

Python pygeoip Exemple

>>> gi = pygeoip.GeoIP('GeoIP.dat')
>>> gi.country_code_by_name('google.com')
'US'
>>> gi.country_code_by_addr('64.233.161.99')
'US'
>>> gi.country_name_by_addr('64.233.161.99')
'United States'
OSP PRO

Python pygeoip Exemple

>>> gi = pygeoip.GeoIP('GeoIPOrg.dat')
>>> gi.org_by_name('dell.com')
'Dell Computer Corporation'
OSP PRO

Python pygeoip Exemple

>>> gi = pygeoip.GeoIP('GeoIPASNum.dat')
>>> gi.asn_by_name('cnn.com')
'AS5662 Turner Broadcasting'
OSP PRO

Python pygeoip Exemple

$ wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
$ gunzip GeoLiteCity.dat.gz
OSP PRO

Python pygeoip Exemple

def coun(attackerip):
	ip_tocoun_db='GeoLiteCity.dat'
	gi = pygeoip.GeoIP(ip_tocoun_db) 
        # IP details are returend as a directory
	rec = gi.record_by_name(attackerip) 
	country = rec['country_name']
	country =str(country)
	return country 
OSP PRO

Python pygeoip Exemple

>>> import pygeoip
>>> gi = pygeoip.GeoIP('GeoIP.dat')
>>> gi.country_name_by_addr('64.233.161.99')
'United States'
OSP PRO

Réponses similaires à “Python pygeoip Exemple”

Questions similaires à “Python pygeoip Exemple”

Plus de réponses similaires à “Python pygeoip Exemple” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code