Exemplo n.º 1
0
def tds_geoip(value):
    "return country flag"
    try:
        IP(value).version()
        cname, ccode = geoip_lookup(value)
        if ccode and cname:
            tag = '<img src="/static/imgs/flags/%s.png" alt="%s"/>' % (ccode,
            cname)
    except ValueError:
        tag = ''
    return mark_safe(tag)
Exemplo n.º 2
0
def tds_geoip(value):
    "return country flag"
    try:
        IP(value).version()
        cname, ccode = geoip_lookup(value)
        if ccode and cname:
            tag = '<img src="/static/imgs/flags/%s.png" alt="%s"/>' % (ccode,
                                                                       cname)
    except ValueError:
        tag = ''
    return mark_safe(tag)
Exemplo n.º 3
0
def relayed_via(headers):
    "display relayed via"
    header_list = headers.split("\n")
    return_value = []
    ipaddr = ""
    for header in header_list:
        match = RECIEVED_RE.match(header)
        if match:
            match = RELAY_HOSTS_RE.findall(header)
            if match:
                match.reverse()
                for address in match:
                    addr = address[0] or address[1] or address[2]
                    try:
                        iptype = IP(addr).iptype()
                    except ValueError:
                        if addr == "127.0.0.1":
                            iptype = "LOOPBACK"
                        else:
                            iptype = "unknown"
                    country_code = "unknown"
                    country_name = ""
                    if not iptype == "LOOPBACK" and addr != ipaddr and addr != "127.0.0.1":
                        ipaddr = addr
                        try:
                            socket.setdefaulttimeout(60)
                            hostname = socket.gethostbyaddr(ipaddr)[0]
                        except (socket.error, socket.gaierror, socket.timeout):
                            if iptype == "PRIVATE":
                                hostname = _("RFC1918 Private address")
                            else:
                                hostname = _("Reverse lookup failed")
                        if iptype != "PRIVATE":
                            country_name, country_code = geoip_lookup(ipaddr)
                        return_value.append(
                            dict(
                                ip_address=ipaddr,
                                hostname=hostname or "&nbsp;",
                                country_code=country_code or "unknown",
                                country_name=country_name or "",
                            )
                        )
    return dict(hosts=return_value)
Exemplo n.º 4
0
def relayed_via(headers):
    "display relayed via"
    header_list = headers.split("\n")
    return_value = []
    ipaddr = ""
    for header in header_list:
        match = RECIEVED_RE.match(header)
        if match:
            match = RELAY_HOSTS_RE.findall(header)
            if match:
                match.reverse()
                for address in match:
                    addr = address[0] or address[1] or address[2]
                    try:
                        iptype = IP(addr).iptype()
                    except ValueError:
                        if addr == '127.0.0.1':
                            iptype = 'LOOPBACK'
                        else:
                            iptype = 'unknown'
                    country_code = "unknown"
                    country_name = ""
                    if (not iptype == "LOOPBACK"
                        and addr != ipaddr
                        and addr != '127.0.0.1'):
                        ipaddr = addr
                        try:
                            socket.setdefaulttimeout(60)
                            hostname = socket.gethostbyaddr(ipaddr)[0]
                        except (socket.error, socket.gaierror, socket.timeout):
                            if iptype == "PRIVATE":
                                hostname = _("RFC1918 Private address")
                            else:
                                hostname = _("Reverse lookup failed")
                        if iptype != "PRIVATE":
                            country_name, country_code = geoip_lookup(ipaddr)
                        return_value.append(dict(ip_address=ipaddr,
                        hostname=hostname or '&nbsp;',
                        country_code=country_code or 'unknown',
                        country_name=country_name or ''))
    return dict(hosts=return_value)