Beispiel #1
0
    def run(self):
        log.debug("Updating mirror database")
        geoip = GeoIP(Config.GEOIP_PATH_V4)

        for status in mirror_statuses(
                unofficial_mirrors=Config.UNOFFICIAL_MIRRORS):
            name = status['mirror']
            if name == "a.pypi.python.org":
                # don't include 'a' in the list of mirrors - it's no mirror after all
                continue
            time_diff = status['time_diff']
            if not isinstance(time_diff, timedelta):
                continue

            log.debug("  Processing mirror '%s'", name)
            record = geoip.record_by_name(name)
            lat = record['latitude']
            lon = record['longitude']

            log.debug("    Age: %d, Lat: %0.5f, Lon: %0.5f",
                      time_diff.total_seconds(), lat, lon)

            try:
                mirror = Mirror.objects.get(name=name)
            except ObjectNotFound:
                mirror = Mirror(name=name)
            mirror.age = time_diff.total_seconds()
            mirror.lat = lat
            mirror.lon = lon

            mirror.save()

        self.redis.set(Config.KEY_LAST_UPDATE, time.time())
        log.debug("Finished updating mirror database")
Beispiel #2
0
    def run(self):
        log.debug("Updating mirror database")
        geoip = GeoIP(Config.GEOIP_PATH_V4)

        for status in mirror_statuses(unofficial_mirrors=Config.UNOFFICIAL_MIRRORS):
            name = status['mirror']
            if name == "a.pypi.python.org":
                # don't include 'a' in the list of mirrors - it's no mirror after all
                continue
            time_diff = status['time_diff']
            if not isinstance(time_diff, timedelta):
                continue

            log.debug("  Processing mirror '%s'", name)
            record = geoip.record_by_name(name)
            lat = record['latitude']
            lon = record['longitude']

            log.debug("    Age: %d, Lat: %0.5f, Lon: %0.5f", time_diff.total_seconds(), lat, lon)

            try:
                mirror = Mirror.objects.get(name=name)
            except ObjectNotFound:
                mirror = Mirror(name=name)
            mirror.age = time_diff.total_seconds()
            mirror.lat = lat
            mirror.lon = lon

            mirror.save()

        self.redis.set(Config.KEY_LAST_UPDATE, time.time())
        log.debug("Finished updating mirror database")
    def calcDistance(self, ipAddr1, ipAddr2):

        gi = GeoIP("c:\\temp\\GeoLiteCity.dat")
        gir1 = gi.record_by_name(ipAddr1)
        gir2 = gi.record_by_name(ipAddr2)
        #Calculate distance
        print "Calculating Distance between IP ", ipAddr1, " and IP ", ipAddr2
        pt1 = geopy.Point(gir1['latitude'], gir1['longitude'])
        pt2 = geopy.Point(gir2['latitude'], gir2['longitude'])
        print "Distance:"
        dist1 = geopy.distance.distance(pt1, pt2).km
        print dist1
        return dist1
Beispiel #4
0
def application(environ, start_response):
    from pygeoip import GeoIP
    from os import path
    from urlparse import parse_qs
    import json

    status = '200 OK'
    ip = environ.get('HTTP_X_REAL_IP',
        environ.get('HTTP_X_FORWARDED_FOR',
            environ.get('REMOTE_ADDR')
        )
    )

    qs = parse_qs(environ.get('QUERY_STRING', ''))
    callback = qs.get('callback', '')

    if any(callback):
        callback = callback[0]
    else:
        callback = None

    if ip:
        filename = path.join(path.dirname(__file__), 'data', 'GeoLiteCity.dat')
        geo = GeoIP(filename)
        record = geo.record_by_name(ip)

        if record:
            response_headers = [('Content-type', 'application/json')]
            start_response(status, response_headers)

            if callback:
                yield '%s(' % callback

            yield json.dumps(record)
            if callback:
                yield ')'

    yield
Beispiel #5
0
class RootWidget(BoxLayout):

    # these link back to the kv file
    user_input = ObjectProperty(None)
    target_str = ObjectProperty(None)
    out_key = ObjectProperty(None)
    out_val = ObjectProperty(None)

    # regex's match ip address or domain name respectively
    ip = compile(r'(?:\d+\.?){4}')
    addr = compile(r'([a-z]+://)?(www\.)?[^ ]+\.[a-z.]*')


    def __init__(self, **kwargs):
        '''
        Initialises the GeoLiteCity database
        '''
        super(RootWidget, self).__init__(**kwargs)
        self.gip = GeoIP('GeoLiteCity.dat')


    def get_info(self):
        '''
        main program logic
        '''
        # get user input
        address = self.user_input.text.lower().strip()
        host_name = ''

        # test for matches
        is_ip = search(self.ip, address)
        is_addr = search(self.addr, address)

        # deal with what we matched
        if is_ip:
            try:
                target = is_ip.string
                ip_info = self.gip.record_by_addr(target)
                # if is_ip, try to resolve host name
                try:
                    host_name = gethostbyaddr(target)[0]
                    print host_name
                except:
                    pass
            except Exception:
                self.target_str.text = "[color=#FF6600][b]Can't Connect..[/b][/color]"
                self.clear_labels()
                return
        elif is_addr:
            try:
                target = is_addr.string
                ip_info = self.gip.record_by_name(target)
                # if is_addr, try to resolve IP
                try:
                    host_name = gethostbyname(target)
                except:
                    pass
            except Exception, e:
                self.target_str.text = "[color=#FF6600][b]Can't Connect..[/b][/color]"
                self.clear_labels()
                return
        else: