示例#1
0
def tds_hostname(value):
    "display hostname"
    hostname = ''
    match = IP_RE.match(value)
    if match:
        if match.groups()[0] == '127.0.0.1':
            hostname = 'localhost'
        else:
            try:
                socket.setdefaulttimeout(60)
                hostname = socket.gethostbyaddr(match.groups()[0])[0]
            except (socket.error, socket.gaierror, socket.timeout):
                hostname = _('unknown')
    return mark_safe(hostname)
示例#2
0
def tds_hostname(value):
    "display hostname"
    hostname = ''
    match = IP_RE.match(value)
    if match:
        if match.groups()[0] == '127.0.0.1':
            hostname = 'localhost'
        else:
            try:
                socket.setdefaulttimeout(60)
                hostname = socket.gethostbyaddr(match.groups()[0])[0]
            except (socket.error, socket.gaierror, socket.timeout):
                hostname = _('unknown')
    return mark_safe(hostname)
示例#3
0
def tds_geoip(value):
    "return country flag"
    tag = ""
    match = IP_RE.match(value)
    if match:
        try:
            gip = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
            ccode = gip.country_code_by_addr(value).lower()
            cname = gip.country_name_by_addr(value)
        except (GeoIP.error, AttributeError):
            ccode = None
            cname = None
        if ccode and cname:
            tag = '<img src="/static/imgs/flags/%s.png" alt="%s"/>' % (ccode,
                                                                       cname)
    return mark_safe(tag)
示例#4
0
def tds_geoip(value):
    "return country flag"
    tag = ""
    match = IP_RE.match(value)
    if match:
        try:
            gip = GeoIP.new(GeoIP.GEOIP_MEMORY_CACHE)
            ccode = gip.country_code_by_addr(value).lower()
            cname = gip.country_name_by_addr(value)
        except (GeoIP.error, AttributeError):
            ccode = None
            cname = None
        if ccode and cname:
            tag = '<img src="/static/imgs/flags/%s.png" alt="%s"/>' % (
            ccode, cname)
    return mark_safe(tag)