between: { ^^ \S+ \: \s flags \= } { ^^ \S+ \: \s flags \= } # 1. Capture interface name, flags and MTU regexp: ^^ (\S+) \: \s flags \= (\d+) \< ( <-[\>]>+ ) \> \s+ mtu \s (\d+) # 2. Capture IPv4 address, netmask, broadcast (if present) regexp: \s+ inet \s (\S+) \s+ netmask \s (\S+) \s+ broadcast \s (\S+) # 3. Capture IPv6 address, prefixlen, scopeid (if present) regexp: \s+ inet6 \s (\S+) \s+ prefixlen \s (\d+) \s+ scopeid \s (\S+) # 4. Capture MAC address and txqueuelen (if present) regexp: \s+ ether \s (<[0..9a..fA..F:]>+) \s+ txqueuelen \s (\d+) generator: < 0 if mtu else 0} valid MTU on {iface}") if ipv4: print(f"assert: 1 IPv4 address {ipv4['addr']} configured on {iface}") print(f"assert: 1 netmask {ipv4['netmask']} on {iface}") print(f"assert: 1 broadcast {ipv4['broadcast']} on {iface}") else: print(f"assert: 0 no IPv4 address on {iface}") if ipv6: print(f"assert: 1 IPv6 address {ipv6['addr']} configured on {iface}") valid_plen = ipv6['prefixlen'].isdigit() and 0 <= int(ipv6['prefixlen']) <= 128 print(f"assert: {valid_plen} valid prefix length on {iface}") print(f"assert: 1 scopeid {ipv6['scopeid']} on {iface}") else: print(f"assert: 0 no IPv6 address on {iface}") if mac: parts = mac['address'].split(':') is_valid_mac = len(parts) == 6 and all(len(p) == 2 for p in parts) print(f"assert: {is_valid_mac} valid MAC format on {iface}") txq_ok = mac['txqueuelen'].isdigit() and int(mac['txqueuelen']) > 0 print(f"assert: {txq_ok} valid txqueuelen on {iface}") else: print(f"assert: 0 no MAC address on {iface}") else: print("assert: 0 no interface line found in this stream") CODE