예제 #1
0
    def get_ips(self):
        """ get ips setted in system local netwoworks which starts with
        127.x.x.x or 192.x.x.x will ignore

        @rtype list
        @return list of ip's in system

        """
        #print(socket.gethostbyname(socket.gethostname()))
        try:
            lines = utils.execute("ip", "address", "|",
                                  utils.bash_command("grep"),
                                  "[[:space:]]inet[[:space:]]")

            pattern = r"inet\s(\d{1,3}[^127|^192]\.\d{1,3}\.\d{1,3}\.\d{1,3})"
            result = []
            for line in lines:
                match = re.match(pattern, line.strip())
                if match:
                    result.append(match.group(1))
            return result

        except ScalixExternalCommandException as exception:
            logger.warning("Could not get ips ", exception)
            return False
예제 #2
0
    def get_ips(self):
        """ get ips setted in system local netwoworks which starts with
        127.x.x.x or 192.x.x.x will ignore

        @rtype list
        @return list of ip's in system

        """
        #print(socket.gethostbyname(socket.gethostname()))
        try:
            lines = utils.execute("ip", "address", "|",
                                  utils.bash_command("grep"),
                                  "[[:space:]]inet[[:space:]]")

            pattern = r"inet\s(\d{1,3}[^127|^192]\.\d{1,3}\.\d{1,3}\.\d{1,3})"
            result = []
            for line in lines:
                match = re.match(pattern, line.strip())
                if match:
                    result.append(match.group(1))
            return result

        except ScalixExternalCommandException as exception:
            logger.warning("Could not get ips ", exception)
            return False
예제 #3
0
def command_exists(command):
    """check if command present in system
    @param command string name of command
    @return True or False

    """
    try:
        execute(command)
        return True
    except ScalixExternalCommandException as exception:
        logger.warning("Command {0} not found ".format(command), exception)
        return False
예제 #4
0
    def get_mx_records(self, domain):
        """ tries to get mx record for domain

        @type bool
        @return True or False

        """
        try:
            lines = utils.execute("dig", "-t", "MX", "+short", domain)
            return [i.strip() for i in lines]
        except ScalixExternalCommandException as exception:
            logger.warning("Could not get MX records ", exception)
            return False
예제 #5
0
    def get_mx_records(self, domain):
        """ tries to get mx record for domain

        @type bool
        @return True or False

        """
        try:
            lines = utils.execute("dig", "-t", "MX", "+short", domain)
            return [i.strip() for i in lines]
        except ScalixExternalCommandException as exception:
            logger.warning("Could not get MX records ", exception)
            return False
예제 #6
0
    def get_java_version(raw=False):
        """get version of installed java virtual machine

        @return string if java installed and available in system or None if java
        not installed

        """
        try:
            lines = utils.execute("java", "-version")
            if raw or not lines:
                return lines
            version = re.search(r'^java version "(.*)"$', lines[0].strip())
            if version:
                return version.group(0)
        except ScalixExternalCommandException as exception:
            logger.warning("Could not get java version", exception)
예제 #7
0
    def get_java_version(raw=False):
        """get version of installed java virtual machine

        @return string if java installed and available in system or None if java
        not installed

        """
        try:
            lines = utils.execute("java", "-version")
            if raw or not lines:
                return lines
            version = re.search(r'^java version "(.*)"$', lines[0].strip())
            if version:
                return version.group(0)
        except ScalixExternalCommandException as exception:
            logger.warning("Could not get java version", exception)
예제 #8
0
    def listening_port(self, port):
        """checks if port opened

        @param port: port number integer
        @return: on success tulip which contain
        (Proto, Recv-Q, Send-Q, Local Address, Foreign Address, State)
        or False
        """

        try:
            result = utils.execute("netstat", "-ln", "|",
                                   utils.bash_command("grep"),
                                   ":{0:d}[^0-9]".format(port))
            return (i for i in result[0].strip().split())

        except ScalixExternalCommandException as exception:
            logger.warning("Could not get port is listening ", exception)
        return ()
예제 #9
0
    def determine_interface(self, ip_str):
        """ get network interface on which ip setted

        @param ip string
        @return string name of interface or None

        """
        try:
            cmd = ["ip", "addr", "show", "|", utils.bash_command("grep"),
                   "[[:space:]]inet[[:space:]]{0}/".format(ip_str), "|",
                   utils.bash_command("head"), "-1", "|",
                   utils.bash_command("gawk"), "'{ print $NF }'"]
            lines = utils.execute(cmd)
            if lines:
                return lines[0].strip()

        except ScalixExternalCommandException as exception:
            logger.warning("Could not determine interface", exception)
예제 #10
0
    def listening_port(self, port):
        """checks if port opened

        @param port: port number integer
        @return: on success tulip which contain
        (Proto, Recv-Q, Send-Q, Local Address, Foreign Address, State)
        or False
        """

        try:
            result = utils.execute("netstat", "-ln", "|",
                                   utils.bash_command("grep"),
                                   ":{0:d}[^0-9]".format(port))
            return (i for i in result[0].strip().split())

        except ScalixExternalCommandException as exception:
            logger.warning("Could not get port is listening ", exception)
        return ()
예제 #11
0
    def determine_interface(self, ip_str):
        """ get network interface on which ip setted

        @param ip string
        @return string name of interface or None

        """
        try:
            cmd = [
                "ip", "addr", "show", "|",
                utils.bash_command("grep"),
                "[[:space:]]inet[[:space:]]{0}/".format(ip_str), "|",
                utils.bash_command("head"), "-1", "|",
                utils.bash_command("gawk"), "'{ print $NF }'"
            ]
            lines = utils.execute(cmd)
            if lines:
                return lines[0].strip()

        except ScalixExternalCommandException as exception:
            logger.warning("Could not determine interface", exception)