Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python pygeoip example

def load_geoip():
    import pygeoip
    from pygeoip.const import MEMORY_CACHE
    
    resource_package = __name__
    filename = pkg_resources.resource_filename(resource_package, 'GeoIP.dat')
    return pygeoip.GeoIP(filename, flags=MEMORY_CACHE) 
Comment

python pygeoip example

pip install pygeoip
Comment

python pygeoip example

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

python pygeoip example

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

python pygeoip example

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

python pygeoip example

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 
Comment

python pygeoip example

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 
Comment

python pygeoip example

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

python pygeoip example

>>> 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'
Comment

python pygeoip example

>>> gi = pygeoip.GeoIP('GeoIPv6.dat')
>>> gi.country_code_by_addr('2a00:1450:400f:802::1006')
'IE'
Comment

python pygeoip example

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

python pygeoip example

$ pip install flask pygeoip
Comment

python pygeoip example

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

PREVIOUS NEXT
Code Example
Python :: jwt authentication python flask 
Python :: django rest framework encrypt passwors 
Python :: importando todo o pacote em python 
Python :: create a typo with python 
Python :: python sort isdigit 
Python :: qlcdnumber set value python 
Python :: dynamic frame latest record 
Python :: how to write a python script to find the value of x at a given y value 
Python :: hashing in python using quadratic probing 
Python :: pandas seaborn distplot 
Python :: jouer à Snake 
Python :: sumx and ABS in power bi 
Python :: h==gmail 
Python :: urllib.error.HTTPError: HTTP Error 502 docker redis 
Python :: python list comprehension with filter example 2 
Python :: star psf 
Python :: ipython widget display 
Python :: knox token lifetime 
Python :: geting columnvalue in python df 
Python :: Start Openvino Python Application at Boot Time using System Service on ubunut 
Python :: logarithmic 2d histogram 
Python :: python last letter of string 
Python :: MyTestCase 
Python :: python plot outline imdbpy 
Python :: get data from s3 bucket python 
Python :: Python String to array using list comprehension 
Python :: List Method: list append vs extend 
Python :: convert integer to binary python 
Python :: networkx draw tripartite graph 
Python :: program to draw rectangle in python 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =