PyFunceble/lookup.py
def nslookup(cls):
        """
        Implementation of UNIX nslookup.
        """

        try:
            # We try to get the addresse information of the given domain or IP.

            if "current_test_data" in PyFunceble.INTERN:  # pragma: no cover
                # The end-user want more information whith his test.

                if not Check().is_ip_valid():
                    # The element we are testing is not an IP.

                    # We request the address informations.
                    request = PyFunceble.socket.getaddrinfo(
                        PyFunceble.INTERN["to_test"],
                        80,
                        0,
                        0,
                        PyFunceble.socket.IPPROTO_TCP,
                    )

                    for sequence in request:
                        # We loop through the sequence returned by the request.

                        # We append the NS informations into the nslookup index.
                        PyFunceble.INTERN["current_test_data"]["nslookup"].append(
                            sequence[-1][0]
                        )
                else:
                    # The element we are testing is an IP.
                    request = PyFunceble.socket.gethostbyaddr(
                        PyFunceble.INTERN["to_test"]
                    )

                    # We append the NS informations into the nslookup index.
                    PyFunceble.INTERN["current_test_data"]["nslookup"][
                        "hostname"
                    ] = request[0]
                    PyFunceble.INTERN["current_test_data"]["nslookup"][
                        "aliases"
                    ] = request[1]
                    PyFunceble.INTERN["current_test_data"]["nslookup"]["ips"] = request[
                        2
                    ]
            else:

                if not Check().is_ip_valid():
                    # The element we are testing is not an IP.
                    PyFunceble.socket.getaddrinfo(
                        PyFunceble.INTERN["to_test"],
                        80,
                        0,
                        0,
                        PyFunceble.socket.IPPROTO_TCP,
                    )
                else:
                    # The element we are testing is an IP.
                    PyFunceble.socket.gethostbyaddr(PyFunceble.INTERN["to_test"])

            # It was done successfuly, we return True.
            # Note: we don't need to read the addresses so we consider as successful
            # as long as there is no error.
            return True

        except (OSError, PyFunceble.socket.herror, PyFunceble.socket.gaierror):
            # One of the listed exception is matched.

            # It was done unsuccesfuly, we return False.
            return False
def nslookup(cls):
        """
        Implementation of UNIX nslookup.
        """

        try:
            # We try to get the addresse information of the given domain or IP.

            if "current_test_data" in PyFunceble.INTERN:  # pragma: no cover
                # The end-user want more information whith his test.

                if not Check().is_ip_valid():
                    # The element we are testing is not an IP.

                    # We request the address informations.
                    request = PyFunceble.socket.getaddrinfo(
                        PyFunceble.INTERN["to_test"],
                        80,
                        0,
                        0,
                        PyFunceble.socket.IPPROTO_TCP,
                    )

                    for sequence in request:
                        # We loop through the sequence returned by the request.

                        # We append the NS informations into the nslookup index.
                        PyFunceble.INTERN["current_test_data"]["nslookup"].append(
                            sequence[-1][0]
                        )
                else:
                    # The element we are testing is an IP.
                    request = PyFunceble.socket.gethostbyaddr(
                        PyFunceble.INTERN["to_test"]
                    )

                    # We append the NS informations into the nslookup index.
                    PyFunceble.INTERN["current_test_data"]["nslookup"][
                        "hostname"
                    ] = request[0]
                    PyFunceble.INTERN["current_test_data"]["nslookup"][
                        "aliases"
                    ] = request[1]
                    PyFunceble.INTERN["current_test_data"]["nslookup"]["ips"] = request[
                        2
                    ]
            else:

                if not Check().is_ip_valid():
                    # The element we are testing is not an IP.
                    PyFunceble.socket.getaddrinfo(
                        PyFunceble.INTERN["to_test"],
                        80,
                        0,
                        0,
                        PyFunceble.socket.IPPROTO_TCP,
                    )
                else:
                    # The element we are testing is an IP.
                    PyFunceble.socket.gethostbyaddr(PyFunceble.INTERN["to_test"])

            # It was done successfuly, we return True.
            # Note: we don't need to read the addresses so we consider as successful
            # as long as there is no error.
            return True

        except (OSError, PyFunceble.socket.herror, PyFunceble.socket.gaierror):
            # One of the listed exception is matched.

            # It was done unsuccesfuly, we return False.
            return False
Implementation of UNIX nslookup.