Exemplo n.º 1
0
    def get_location(self, ipaddr):
        with self.browser:

            content = self.browser.readurl('http://www.geolocip.com/?s[ip]=%s&commit=locate+IP!' % str(ipaddr))

            if content is None:
                raise BrowserUnavailable()

            tab = {}
            last_line = ''
            line = ''
            for line in content.split('\n'):
                if len(line.split('<dd>')) > 1:
                    key = last_line.split('<dt>')[1].split('</dt>')[0][0:-2]
                    value = line.split('<dd>')[1].split('</dd>')[0]
                    tab[key] = value
                last_line = line
            iploc = IpLocation(ipaddr)
            iploc.city = tab['City']
            iploc.region = tab['Region']
            iploc.zipcode = tab['Postal code']
            iploc.country = tab['Country name']
            if tab['Latitude'] != '':
                iploc.lt = float(tab['Latitude'])
            else:
                iploc.lt = 0.0
            if tab['Longitude'] != '':
                iploc.lg = float(tab['Longitude'])
            else:
                iploc.lg = 0.0
            #iploc.host = 'NA'
            #iploc.tld = 'NA'
            #iploc.isp = 'NA'

            return iploc
Exemplo n.º 2
0
    def get_location(self, ipaddr):
        res = self.browser.location('http://ip-api.com/json/%s' % ipaddr.encode('utf-8'))
        jres = json.loads(res.text)

        if "status" in jres and jres["status"] == "fail":
            raise Exception("IPAPI failure : %s" % jres["message"])

        iploc = IpLocation(ipaddr)
        iploc.city = u'%s'%jres['city']
        iploc.region = u'%s'%jres['regionName']
        iploc.zipcode = u'%s'%jres['zip']
        iploc.country = u'%s'%jres['country']
        if jres['lat'] != '':
            iploc.lt = float(jres['lat'])
        else:
            iploc.lt = 0.0
        if jres['lon'] != '':
            iploc.lg = float(jres['lon'])
        else:
            iploc.lg = 0.0
        #iploc.host = 'NA'
        #iploc.tld = 'NA'
        if 'isp' in jres:
            iploc.isp = u'%s'%jres['isp']

        return iploc
Exemplo n.º 3
0
    def get_location(self, ipaddr):
        with self.browser:

            content = self.browser.readurl('http://ipinfodb.com/ip_locator.php?ip=%s' % str(ipaddr))

            if content is None:
                raise BrowserUnavailable()

            if 'Invalid IP or domain name' in content:
                raise Exception('Bad parameter')
            else:
                tab = {'City' : 'NA' ,\
                        'Country name' : 'NA' ,\
                        'Region' : 'NA' ,\
                        'Latitude' : 'NA' ,\
                        'Longitude' : 'NA' ,\
                        'hostname' : 'NA' ,\
                        'zipcode' : 'NA'}
                line = ''
                for line in content.split('\n'):
                    if '<li>' in line:
                        if 'Country :' in line:
                            tab['Country name'] = line.split('Country : ')[1].split('<')[0]
                        elif "State/Province :" in line:
                            tab['Region'] = line.split('State/Province : ')[1].split('<')[0]
                        elif "City :" in line:
                            tab['City'] = line.split('City : ')[1].split('<')[0]
                        elif "Latitude :" in line:
                            tab['Latitude'] = line.split('Latitude : ')[1].split('<')[0]
                        elif "Longitude :" in line:
                            tab['Longitude'] = line.split('Longitude : ')[1].split('<')[0]
                        elif "Hostname :" in line:
                            tab['hostname'] = line.split('Hostname : ')[1].split('<')[0]
                iploc = IpLocation(ipaddr)
                iploc.city = tab['City'].decode('utf-8')
                iploc.region = tab['Region']
                iploc.zipcode = tab['zipcode']
                iploc.country = tab['Country name']
                try :
                    iploc.lt = float(tab['Latitude'])
                    iploc.lg = float(tab['Longitude'])
                except ValueError:
                    pass
                iploc.host = tab['hostname']
                iploc.tld = tab['hostname'].split('.')[-1]
                #iploc.isp = 'NA'

                return iploc
Exemplo n.º 4
0
    def get_location(self, ipaddr):
        self.browser.location("http://ipinfodb.com/ip_locator.php")
        self.browser.select_form(nr=0)
        self.browser['ip'] = str(ipaddr)
        response = self.browser.submit()
        document = self.browser.get_document(response)

        tab = {
            'City': 'NA',
            'Country name': 'NA',
            'Region': 'NA',
            'Latitude': 'NA',
            'Longitude': 'NA',
            'hostname': 'NA',
            'zipcode': 'NA'
        }
        for li in document.getiterator('li'):
            txt = li.text_content()
            if 'Country :' in txt:
                tab['Country name'] = txt.split('Country : ')[1].split('<')[0]
            elif "State/Province :" in txt:
                tab['Region'] = txt.split('State/Province : ')[1].split('<')[0]
            elif "City :" in txt:
                tab['City'] = txt.split('City : ')[1].split('<')[0]
            elif "Latitude :" in txt:
                tab['Latitude'] = txt.split('Latitude : ')[1].split('<')[0]
            elif "Longitude :" in txt:
                tab['Longitude'] = txt.split('Longitude : ')[1].split('<')[0]
            elif "Hostname :" in txt:
                tab['hostname'] = txt.split('Hostname : ')[1].split('<')[0]
        iploc = IpLocation(ipaddr)
        iploc.city = unicode(tab['City'].decode('utf-8'))
        iploc.region = unicode(tab['Region'])
        iploc.zipcode = unicode(tab['zipcode'])
        iploc.country = unicode(tab['Country name'])
        try:
            iploc.lt = float(tab['Latitude'])
            iploc.lg = float(tab['Longitude'])
        except ValueError:
            pass
        iploc.host = unicode(tab['hostname'])
        iploc.tld = unicode(tab['hostname'].split('.')[-1])
        #iploc.isp = 'NA'

        return iploc
Exemplo n.º 5
0
    def get_location(self, ipaddr):
        res = self.browser.location('https://freegeoip.net/json/%s' % ipaddr.encode('utf-8'))
        jres = json.loads(res.text)

        iploc = IpLocation(ipaddr)
        iploc.city = u'%s'%jres['city']
        iploc.region = u'%s'%jres['region_name']
        iploc.zipcode = u'%s'%jres['zip_code']
        iploc.country = u'%s'%jres['country_name']
        if jres['latitude'] != '':
            iploc.lt = float(jres['latitude'])
        else:
            iploc.lt = 0.0
        if jres['longitude'] != '':
            iploc.lg = float(jres['longitude'])
        else:
            iploc.lg = 0.0

        return iploc
Exemplo n.º 6
0
    def get_location(self, ipaddr):
        self.browser.location("http://ipinfodb.com/ip_locator.php")
        self.browser.select_form(nr=0)
        self.browser["ip"] = str(ipaddr)
        response = self.browser.submit()
        document = self.browser.get_document(response)

        tab = {
            "City": "NA",
            "Country name": "NA",
            "Region": "NA",
            "Latitude": "NA",
            "Longitude": "NA",
            "hostname": "NA",
            "zipcode": "NA",
        }
        for li in document.getiterator("li"):
            txt = li.text_content()
            if "Country :" in txt:
                tab["Country name"] = txt.split("Country : ")[1].split("<")[0]
            elif "State/Province :" in txt:
                tab["Region"] = txt.split("State/Province : ")[1].split("<")[0]
            elif "City :" in txt:
                tab["City"] = txt.split("City : ")[1].split("<")[0]
            elif "Latitude :" in txt:
                tab["Latitude"] = txt.split("Latitude : ")[1].split("<")[0]
            elif "Longitude :" in txt:
                tab["Longitude"] = txt.split("Longitude : ")[1].split("<")[0]
            elif "Hostname :" in txt:
                tab["hostname"] = txt.split("Hostname : ")[1].split("<")[0]
        iploc = IpLocation(ipaddr)
        iploc.city = unicode(tab["City"].decode("utf-8"))
        iploc.region = unicode(tab["Region"])
        iploc.zipcode = unicode(tab["zipcode"])
        iploc.country = unicode(tab["Country name"])
        try:
            iploc.lt = float(tab["Latitude"])
            iploc.lg = float(tab["Longitude"])
        except ValueError:
            pass
        iploc.host = unicode(tab["hostname"])
        iploc.tld = unicode(tab["hostname"].split(".")[-1])
        # iploc.isp = 'NA'

        return iploc
Exemplo n.º 7
0
    def get_location(self, ipaddr):
        res = self.browser.location('https://freegeoip.net/json/%s' % ipaddr.encode('utf-8'))
        jres = json.loads(res.text)

        iploc = IpLocation(ipaddr)
        iploc.city = u'%s'%jres['city']
        iploc.region = u'%s'%jres['region_name']
        iploc.zipcode = u'%s'%jres['zip_code']
        iploc.country = u'%s'%jres['country_name']
        if jres['latitude'] != '':
            iploc.lt = float(jres['latitude'])
        else:
            iploc.lt = 0.0
        if jres['longitude'] != '':
            iploc.lg = float(jres['longitude'])
        else:
            iploc.lg = 0.0

        return iploc
Exemplo n.º 8
0
    def get_location(self, ipaddr):
        self.browser.location("http://ipinfodb.com/ip_locator.php")
        self.browser.select_form(nr=0)
        self.browser['ip'] = str(ipaddr)
        response = self.browser.submit()
        document = self.browser.get_document(response)

        tab = {'City' : 'NA' ,
                'Country name' : 'NA' ,
                'Region' : 'NA' ,
                'Latitude' : 'NA' ,
                'Longitude' : 'NA' ,
                'hostname' : 'NA' ,
                'zipcode' : 'NA'}
        for li in document.getiterator('li'):
            txt = li.text_content()
            if 'Country :' in txt:
                tab['Country name'] = txt.split('Country : ')[1].split('<')[0]
            elif "State/Province :" in txt:
                tab['Region'] = txt.split('State/Province : ')[1].split('<')[0]
            elif "City :" in txt:
                tab['City'] = txt.split('City : ')[1].split('<')[0]
            elif "Latitude :" in txt:
                tab['Latitude'] = txt.split('Latitude : ')[1].split('<')[0]
            elif "Longitude :" in txt:
                tab['Longitude'] = txt.split('Longitude : ')[1].split('<')[0]
            elif "Hostname :" in txt:
                tab['hostname'] = txt.split('Hostname : ')[1].split('<')[0]
        iploc = IpLocation(ipaddr)
        iploc.city = unicode(tab['City'].decode('utf-8'))
        iploc.region = unicode(tab['Region'])
        iploc.zipcode = unicode(tab['zipcode'])
        iploc.country = unicode(tab['Country name'])
        try :
            iploc.lt = float(tab['Latitude'])
            iploc.lg = float(tab['Longitude'])
        except ValueError:
            pass
        iploc.host = unicode(tab['hostname'])
        iploc.tld = unicode(tab['hostname'].split('.')[-1])
        #iploc.isp = 'NA'

        return iploc
Exemplo n.º 9
0
    def get_location(self, ipaddr):
        res = self.browser.location(u'http://ip-api.com/json/%s' % ipaddr)
        jres = json.loads(res.text)

        if "status" in jres and jres["status"] == "fail":
            raise Exception("IPAPI failure : %s" % jres["message"])

        iploc = IpLocation(ipaddr)
        iploc.city = u'%s' % jres['city']
        iploc.region = u'%s' % jres['regionName']
        iploc.zipcode = u'%s' % jres['zip']
        iploc.country = u'%s' % jres['country']
        if jres['lat'] != '':
            iploc.lt = float(jres['lat'])
        else:
            iploc.lt = 0.0
        if jres['lon'] != '':
            iploc.lg = float(jres['lon'])
        else:
            iploc.lg = 0.0
        #iploc.host = 'NA'
        #iploc.tld = 'NA'
        if 'isp' in jres:
            iploc.isp = u'%s' % jres['isp']

        return iploc