1

I've searched extensively for an answer to my dilemma so I hope someone is able to assist. I'm trying to retrieve an IP address from a Linux based system then display the IP address on the screen with Python - here's what I have so far:

import tkinter
import subprocess
import os
import re
pattern = re.compile("^([A-Z][0-9]+)+$")
test = "10.11.10.1"
cmd = subprocess.check_output("ifconfig eno1", shell=True)
cmd = cmd.decode()
cmd = cmd.splitlines()
ip = re.match('[0-9]+', cmd[1])
if ip:
    print(ip.group(0))

If I print(cmd) after the decode is prints several lines of output from the ifconfig command, the second line contains the IP address I'm after so this information is displayed if I print(cmd[1]). If I substitute test for cmd[1] the script prints "10" as expected If I change the pattern matching line to read

ip = pattern.match(cmd[1])

I get the same result, however if I change it to

ip = re.match(".*", cmd[1])

it prints out the same thing as does print(cmd[1]) so why does it match .* but neither characters or numbers? Is it possible that the raw data is in some other format than ascii??

0 Answers0