Beispiel #1
0
    def parse(self, out):
        if len(out) == 0:
            return
        intf = out.split()[0]
        if intf[len(intf) - 1] == ':':
            intf = intf[0:len(intf) - 1]

        i = rcIfconfig.interface(intf)
        self.intf.append(i)

        # defaults
        i.link_encap = ''
        i.scope = ''
        i.bcast = ''
        i.mask = ''
        i.mtu = ''
        i.ipaddr = ''
        i.ip6addr = []
        i.ip6mask = []
        i.hwaddr = ''
        if i.name in self.hwaddr:
            i.hwaddr = self.hwaddr[i.name]
        i.flag_up = False
        i.flag_broadcast = False
        i.flag_running = False
        i.flag_multicast = False
        i.flag_loopback = False

        prev = ''
        for w in out.split():
            if 'broadcast' in prev:
                i.bcast = w
            elif 'netmask' in prev:
                if w == '0':
                    i.mask = "0.0.0.0"
                elif len(w) == 8:
                    i.mask = "%d.%d.%d.%d" % (int(w[0:2], 16), int(
                        w[2:4], 16), int(w[4:6], 16), int(w[6:8], 16))
                else:
                    raise ex.excError("malformed ifconfig %s netmask: %s" %
                                      (intf, w))
            elif 'inet' == prev:
                i.ipaddr = w
            elif 'inet6' == prev:
                i.ip6addr += [w]
            elif 'prefix' == prev:
                i.ip6mask += [w]

            if 'UP' in w:
                i.flag_up = True
            if 'BROADCAST' in w:
                i.flag_broadcast = True
            if 'RUNNING' in w:
                i.flag_running = True
            if 'MULTICAST' in w:
                i.flag_multicast = True
            if 'LOOPBACK' in w:
                i.flag_loopback = True

            prev = w
Beispiel #2
0
    def parse(self, intf, intf_cf):
        if intf_cf.IPAddress is None:
            return
        i = rcIfconfig.interface(intf.NetConnectionID)
        self.intf.append(i)

        # defaults
        i.link_encap = ''
        i.scope = ''
        i.bcast = ''
        i.mask = []
        i.mtu = intf_cf.MTU
        i.ipaddr = []
        i.ip6addr = []
        i.ip6mask = []
        i.hwaddr = intf_cf.MACAddress
        try:
            i.flag_up = intf.NetEnabled
        except:
            i.flag_up = False
        i.flag_broadcast = False
        i.flag_running = False
        i.flag_multicast = False
        i.flag_loopback = False

        for idx, ip in enumerate(intf_cf.IPAddress):
            if ":" in ip:
                i.ip6addr.append(ip)
                i.ip6mask.append(intf_cf.IPsubnet[idx])
            else:
                i.ipaddr.append(ip)
                i.mask.append(intf_cf.IPsubnet[idx])
Beispiel #3
0
    def parse_ifconfig(self, out):
        prev = ''
        prevprev = ''
        for w in out.split():
            if w == 'Link':
                i = rcIfconfig.interface(prev)
                self.intf.append(i)

                # defaults
                i.link_encap = ''
                i.scope = ''
                i.bcast = ''
                i.mask = ''
                i.mtu = ''
                i.ipaddr = ''
                i.ip6addr = []
                i.ip6mask = []
                i.hwaddr = ''
                i.flag_up = False
                i.flag_broadcast = False
                i.flag_running = False
                i.flag_multicast = False
                i.flag_loopback = False
                i.flag_no_carrier = False
            elif 'encap:' in w:
                (null, i.link_encap) = w.split(':')
            elif 'Scope:' in w:
                (null, i.scope) = w.split(':')
            elif 'Bcast:' in w:
                (null, i.bcast) = w.split(':')
            elif 'Mask:' in w:
                (null, i.mask) = w.split(':')
            elif 'MTU:' in w:
                (null, i.mtu) = w.split(':')

            if 'inet' == prev and 'addr:' in w:
                (null, i.ipaddr) = w.split(':')
            if 'inet6' == prevprev and 'addr:' == prev:
                (ip6addr, ip6mask) = w.split('/')
                i.ip6addr += [ip6addr]
                i.ip6mask += [ip6mask]
            if 'HWaddr' == prev:
                i.hwaddr = w
            if 'UP' == w:
                i.flag_up = True
            if 'BROADCAST' == w:
                i.flag_broadcast = True
            if 'RUNNING' == w:
                i.flag_running = True
            if 'MULTICAST' == w:
                i.flag_multicast = True
            if 'LOOPBACK' == w:
                i.flag_loopback = True
            if 'NO-CARRIER' == w:
                i.flag_no_carrier = True

            prevprev = prev
            prev = w
Beispiel #4
0
    def parse(self, out):
        i = None
        for l in out.split("\n"):
            if l == '': break
            if l[0] != '\t':
                i = self.set_hwaddr(i)
                (ifname, ifstatus) = l.split(': ')

                i = rcIfconfig.interface(ifname)
                self.intf.append(i)

                # defaults
                i.link_encap = ''
                i.scope = ''
                i.bcast = ''
                i.mask = ''
                i.mtu = ''
                i.ipaddr = ''
                i.ip6addr = []
                i.ip6mask = []
                i.hwaddr = ''
                i.groupname = ''
                i.flag_up = False
                i.flag_broadcast = False
                i.flag_running = False
                i.flag_multicast = False
                i.flag_ipv4 = False
                i.flag_ipv6 = False
                i.flag_loopback = False

                if 'UP' in ifstatus: i.flag_up = True
                if 'DEPRECATED' in ifstatus: i.flag_deprecated = True
                if 'BROADCAST' in ifstatus: i.flag_broadcast = True
                if 'RUNNING' in ifstatus: i.flag_running = True
                if 'MULTICAST' in ifstatus: i.flag_multicast = True
                if 'IPv4' in ifstatus: i.flag_ipv4 = True
                if 'IPv6' in ifstatus: i.flag_ipv6 = True
            else:
                n = 0
                w = l.split()
                while n < len(w):
                    [p, v] = w[n:n + 2]
                    if p == 'inet': i.ipaddr = v
                    elif p == 'netmask': i.mask = v
                    elif p == 'broadcast': i.bcast = v
                    elif p == 'ether': i.hwaddr = v
                    elif p == 'groupname': i.groupname = v
                    elif p == 'inet6':
                        (a, m) = v.split('/')
                        i.ip6addr += [a]
                        i.ip6mask += [m]
                    n += 2
        i = self.set_hwaddr(i)
Beispiel #5
0
    def parse(self, out):
        i = None
        for l in out.split("\n"):
            if l == '': continue
            if l[0] != ' ':
                i = self.set_hwaddr(i)
                (ifname, ifstatus) = l.split(': ')

                i = rcIfconfig.interface(ifname)
                self.intf.append(i)

                # defaults
                i.link_encap = ''
                i.scope = ''
                i.bcast = []
                i.mtu = []
                i.mask = []
                i.ipaddr = []
                i.ip6addr = []
                i.ip6mask = []
                i.hwaddr = ''
                i.flag_up = False
                i.flag_broadcast = False
                i.flag_running = False
                i.flag_multicast = False
                i.flag_ipv4 = False
                i.flag_ipv6 = False
                i.flag_loopback = False

                if 'UP' in ifstatus: i.flag_up = True
                elif 'BROADCAST' in ifstatus: i.flag_broadcast = True
                elif 'RUNNING' in ifstatus: i.flag_running = True
                elif 'MULTICAST' in ifstatus: i.flag_multicast = True
                elif 'IPv4' in ifstatus: i.flag_ipv4 = True
                elif 'IPv6' in ifstatus: i.flag_ipv6 = True
            else:
                n = 0
                w = l.split()
                while n < len(w):
                    [p, v] = w[n:n + 2]
                    if p == 'inet':
                        i.ipaddr.append(v)
                        i.mask.append(ipv4_bitmask(w[n + 3]))
                    elif p == 'ipmtu':
                        i.mtu.append(v)
                    elif p == 'inet6':
                        (a, m) = v.split('/')
                        i.ip6addr += [a]
                        i.ip6mask += [m]
                    n += 2
        i = self.set_hwaddr(i)
Beispiel #6
0
    def parse(self, out):
        prev = ''
        prevprev = ''
        for w in out.split():
            if 'flags=' in w:
                i = rcIfconfig.interface(prev.replace(':', ''))
                self.intf.append(i)

                # defaults
                i.link_encap = ''
                i.scope = ''
                i.bcast = ''
                i.mtu = ''
                i.ipaddr = []
                i.mask = []
                i.ip6addr = []
                i.ip6mask = []
                i.hwaddr = ''
                i.flag_up = False
                i.flag_broadcast = False
                i.flag_running = False
                i.flag_multicast = False
                i.flag_loopback = False

                flags = w.split('<')[1].split('>')[0].split(',')
                if 'UP' in flags:
                    i.flag_up = True
                if 'BROADCAST' in flags:
                    i.flag_broadcast = True
                if 'RUNNING' in flags:
                    i.flag_running = True
                if 'MULTICAST' in flags:
                    i.flag_multicast = True
                if 'LOOPBACK' in flags:
                    i.flag_loopback = True
            elif 'inet' == prev:
                i.ipaddr += [w]
            elif 'inet6' == prev:
                i.ip6addr += [w.split('%')[0]]
            elif 'netmask' == prev:
                i.mask += [w]
            elif 'prefixlen' == prev:
                i.ip6mask += [w]
            elif 'ether' == prev:
                i.hwaddr = w

            prevprev = prev
            prev = w
Beispiel #7
0
    def parse_ip(self, out):
        for line in out.splitlines():
            if len(line) == 0:
                continue
            if line[0] != " ":
                """
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
                """
                _line = line.split()
                ifname = _line[1].strip(":")
                if "@" in ifname:
                    ifkname = ifname[ifname.index("@"):]
                    ifname = ifname[:ifname.index("@")]
                else:
                    ifkname = None
                i = rcIfconfig.interface(ifname)
                i.ifkname = ifkname

                # defaults
                i.link_encap = ''
                i.scope = []
                i.bcast = []
                i.mask = []
                i.mtu = ''
                i.ipaddr = []
                i.ip6addr = []
                i.ip6mask = []
                i.hwaddr = ''
                i.flag_up = False
                i.flag_broadcast = False
                i.flag_running = False
                i.flag_multicast = False
                i.flag_loopback = False
                i.flag_no_carrier = False

                self.intf.append(i)

                prev = ''
                for w in _line:
                    if 'mtu' == prev:
                        i.mtu = w
                    elif w.startswith('<'):
                        w = w.strip('<').strip('>')
                        flags = w.split(',')
                        for w in flags:
                            if 'UP' == w:
                                i.flag_up = True
                            if 'BROADCAST' == w:
                                i.flag_broadcast = True
                            if 'RUNNING' == w:
                                i.flag_running = True
                            if 'MULTICAST' == w:
                                i.flag_multicast = True
                            if 'LOOPBACK' == w:
                                i.flag_loopback = True
                            if 'NO-CARRIER' == w:
                                i.flag_no_carrier = True

                    prev = w
            elif line.strip().startswith("link"):
                """
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
                """
                _line = line.split()
                prev = ''
                for w in _line:
                    if 'link/' in w:
                        i.link_encap = w.split('/')[1]
                    elif 'link/ether' == prev:
                        i.hwaddr = w
                    prev = w
            elif line.strip().startswith("inet"):
                """
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
                """
                _line = line.split()
                if "global" in line and ":" in _line[-1]:
                    # clone parent intf and reset inet fields
                    ifname = line.split()[-1]
                    _i = copy.copy(i)
                    _i.name = ifname
                    _i.scope = []
                    _i.bcast = []
                    _i.mask = []
                    _i.ipaddr = []
                    _i.ip6addr = []
                    _i.ip6mask = []
                    self.intf.append(_i)
                else:
                    _i = i

                prev = ''
                for w in _line:
                    if 'inet' == prev:
                        try:
                            ipaddr, mask = w.split('/')
                        except:
                            # tun for example
                            continue
                        _i.ipaddr += [ipaddr]
                        _i.mask += [cidr_to_dotted(mask)]
                    elif 'inet6' == prev:
                        try:
                            ip6addr, ip6mask = w.split('/')
                        except:
                            # tun for example
                            continue
                        _i.ip6addr += [ip6addr]
                        _i.ip6mask += [ip6mask]
                    elif 'brd' == prev and 'inet' in line:
                        _i.bcast += [w]
                    elif 'scope' == prev and 'inet' in line:
                        _i.scope += [w]

                    prev = w