def METHOD_NAME(self):
    try:
        host = self.request.get_header('host').split(':')[0]
    except AttributeError:
        return False  # no host header
    try:
        socket.inet_aton(host)
        return True
    except Exception:
        if host.lower() == 'localhost':
            return True
    return False