示例#1
0
def list_iptables(version=constants.IP_VERSION_4, namespace=None):
    cmd = ''
    if namespace:
        cmd = 'sudo ip netns exec %s ' % namespace
    cmd += ('iptables-save' if version == constants.IP_VERSION_4 else
            'ip6tables-save')
    return shell.execute(cmd).stdout
示例#2
0
def get_ncat_version(ssh_client=None):
    cmd = "ncat --version 2>&1"
    try:
        version_result = shell.execute(cmd, ssh_client=ssh_client).stdout
    except exceptions.ShellCommandFailed:
        m = None
    else:
        m = re.match(r"Ncat: Version ([\d.]+) *.", version_result)
    # NOTE(slaweq): by default lets assume we have ncat 7.60 which is in Ubuntu
    # 18.04 which is used on u/s gates
    return distutils.version.StrictVersion(m.group(1) if m else '7.60')
示例#3
0
def arp_table(namespace=None):
    # 192.168.0.16  0x1  0x2  dc:a6:32:06:56:51  *  enp0s31f6
    regex_str = (r"([^ ]+)\s+(0x\d+)\s+(0x\d+)\s+(\w{2}\:\w{2}\:\w{2}\:\w{2}\:"
                 r"\w{2}\:\w{2})\s+([\w+\*]+)\s+([\-\w]+)")
    regex = re.compile(regex_str)
    arp_table = []
    cmd = ""
    if namespace:
        cmd = "sudo ip netns exec %s " % namespace
    cmd += "cat /proc/net/arp"
    arp_entries = shell.execute(cmd).stdout.split("\n")
    for line in arp_entries:
        m = regex.match(line)
        if m:
            arp_table.append(ARPregister(
                ip_address=m.group(1), hw_type=m.group(2),
                flags=m.group(3), mac_address=m.group(4),
                mask=m.group(5), device=m.group(6)))
    return arp_table
示例#4
0
 def execute(self, obj, *command):
     command_line = self.get_command(obj, *command)
     return shell.execute(command_line, ssh_client=self.ssh_client,
                          timeout=self.timeout).stdout
示例#5
0
def list_listening_sockets(namespace=None):
    cmd = ''
    if namespace:
        cmd = 'sudo ip netns exec %s ' % namespace
    cmd += 'netstat -nlp'
    return shell.execute(cmd).stdout