mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
Deprecate calling sub process 'ifconfig' use netifaces instead
This commit is contained in:
parent
998010cb1b
commit
9b784bb656
1 changed files with 11 additions and 5 deletions
|
@ -10,6 +10,7 @@ import platform
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
import netifaces
|
||||||
from uuid import getnode as get_mac
|
from uuid import getnode as get_mac
|
||||||
|
|
||||||
import cpuinfo
|
import cpuinfo
|
||||||
|
@ -460,9 +461,14 @@ class System:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ip_addresses():
|
def ip_addresses():
|
||||||
arr = []
|
arr = []
|
||||||
for iface in psutil.net_io_counters(pernic=True):
|
for iface in netifaces.interfaces():
|
||||||
f = os.popen('ifconfig {0} | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'.format(iface))
|
link = None
|
||||||
ip = str(f.read()).replace('\n', '')
|
try:
|
||||||
|
link = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]
|
||||||
|
except:
|
||||||
|
link = None
|
||||||
|
if link is not None:
|
||||||
|
ip = link['addr']
|
||||||
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$',
|
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$',
|
||||||
ip) and str(ip) != 'localhost' and str(ip) != '127.0.0.1':
|
ip) and str(ip) != 'localhost' and str(ip) != '127.0.0.1':
|
||||||
arr.append(ip)
|
arr.append(ip)
|
||||||
|
|
Loading…
Reference in a new issue