mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-10 01:05:42 +00:00
addressManager: remove old style ifconfig
This commit is contained in:
parent
2f68d6a76f
commit
ea45451c28
1 changed files with 49 additions and 65 deletions
|
@ -58,23 +58,7 @@ class addressManager():
|
||||||
foundAddresses.append(line[k+1:])
|
foundAddresses.append(line[k+1:])
|
||||||
else:
|
else:
|
||||||
# on Raspberry
|
# on Raspberry
|
||||||
cfg_useOldStyleIfconfig = 0
|
# instead of the deprecated ifconfig, use "ip addr"
|
||||||
if (cfg_useOldStyleIfconfig!=0):
|
|
||||||
result = subprocess.run(["ifconfig"], capture_output=True, text=True)
|
|
||||||
if (len(result.stderr)>0):
|
|
||||||
print(result.stderr)
|
|
||||||
else:
|
|
||||||
lines = result.stdout.split("\n")
|
|
||||||
for line in lines:
|
|
||||||
if (line.strip().find("inet6")>0):
|
|
||||||
k = line.strip().find("fe80::") # the beginning of the IPv6
|
|
||||||
if (k>0):
|
|
||||||
sIpWithText = line[k+1:]
|
|
||||||
x = sIpWithText.find(" ") # the space is the end of the IPv6
|
|
||||||
sIp = sIpWithText[0:x]
|
|
||||||
# print("[addressManager] IP=>" + sIp + "<")
|
|
||||||
foundAddresses.append(sIp)
|
|
||||||
else: # instead of the deprecated ifconfig, use "ip addr"
|
|
||||||
result = subprocess.run(["ip", "addr"], capture_output=True, text=True)
|
result = subprocess.run(["ip", "addr"], capture_output=True, text=True)
|
||||||
if (len(result.stderr)>0):
|
if (len(result.stderr)>0):
|
||||||
print(result.stderr)
|
print(result.stderr)
|
||||||
|
|
Loading…
Reference in a new issue