#! /usr/bin/env python3 import utilities, os, sys, re def read_from_command(command: str) -> list: try: with os.popen(command, 'r') as pipe: return list(map(str.rstrip, pipe.readlines())) #return [l.rstrip for l in pipe.readlines()] print(com_list) except OSError: print("Kann Program nicht auslesen", file=sys.stderr) def extract_ip(lines: list) -> list: regex = r'.*inet\s(([0-9]{1,3}\.){3}[0-9]{1,3})' addresse= [] for line in lines: match = re.match(regex,line) if match: #print("Gesamte IP :", match.group(1)) #print("3. Oktett :", match.group(2)) addresse.append(match.group(1)) #print(line) return addresse def main(): lines = read_from_command("ip address show") local_ip = extract_ip(lines) print("Aktuelle Adressen : ", local_ip) utilities.hide_exception(main)