human
Complete this python program:
def check_internet_off(original_function):
assistant
#Here is the Python program you requested.

    """Wraps ``original_function``, which in most cases is assumed
    to be a `socket.socket` method, to raise an `IOError` for any operations
    on non-local AF_INET sockets.
    """
    def new_function(*args, **kwargs):
        if isinstance(args[0], socket.socket):
            if (not (args[0].family in (socket.AF_INET, socket.AF_INET6))):
                return original_function(*args, **kwargs)
            host = args[1][0]
            addr_arg = 1
            valid_hosts = (u'localhost', u'127.0.0.1', u'::1')
        else:
            if (not (isinstance(args[0], tuple) and (len(args[0]) == 2))):
                return original_function(*args, **kwargs)
            host = args[0][0]
            addr_arg = 0
            valid_hosts = (u'localhost', u'127.0.0.1')
        hostname = socket.gethostname()
        fqdn = socket.getfqdn()
        if (host in (hostname, fqdn)):
            host = u'localhost'
            new_addr = (host, args[addr_arg][1])
            args = ((args[:addr_arg] + (new_addr,)) + args[(addr_arg + 1):])
        if any([(h in host) for h in valid_hosts]):
            return original_function(*args, **kwargs)
        else:
            raise IOError(u'An    attempt    was    made    to    connect    to    the    internet    by    a    test    that    was    not    marked    `remote_data`.')
    return new_function