diff --git a/opt/ahenk/base/registration/Registration.py b/opt/ahenk/base/registration/Registration.py index 9ad9052..08d412c 100644 --- a/opt/ahenk/base/registration/Registration.py +++ b/opt/ahenk/base/registration/Registration.py @@ -4,16 +4,12 @@ import datetime import json -import socket import uuid -import os -import platform -import psutil from uuid import getnode as get_mac from base.Scope import Scope -from base.system.system import System from base.messaging.AnonymousMessager import AnonymousMessager +from base.system.system import System class Registration(): @@ -99,8 +95,8 @@ class Registration(): def get_registration_params(self): params = { - 'ipAddresses': str(System.Hardware.Network.ip_addresses()).replace('\'localhost\'', '').replace('\'127.0.0.1\'', ''), - 'macAddresses': System.Hardware.mac_address(), + 'ipAddresses': System.Hardware.Network.ip_addresses(), + 'macAddresses': System.Hardware.Network.mac_addresses(), 'hostname': System.Os.hostname(), 'os.name': System.Os.name(), 'os.version': System.Os.version(), @@ -110,8 +106,8 @@ class Registration(): 'os.distributionVersion': System.Os.distribution_version(), 'os.architecture': System.Os.architecture(), 'hardware.cpu.architecture': System.Hardware.Cpu.architecture(), - 'hardware..cpu.logicalCoreCount': System.Hardware.Cpu.logical_core_count(), - 'hardware..cpu.physicalCoreCount': System.Hardware.Cpu.physical_core_count(), + 'hardware.cpu.logicalCoreCount': System.Hardware.Cpu.logical_core_count(), + 'hardware.cpu.physicalCoreCount': System.Hardware.Cpu.physical_core_count(), 'hardware.disk.total': System.Hardware.Disk.total(), 'hardware.disk.used': System.Hardware.Disk.used(), 'hardware.disk.free': System.Hardware.Disk.free(), @@ -143,20 +139,3 @@ class Registration(): def generate_password(self): return uuid.uuid4() - - """ - def get_ip_address(self): - f = os.popen('ifconfig eth0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1') - return f.read() - - - #TODO disabled because of netifaces dependency - def get_ipAddresses(self): - self.logger.debug('[Registration] looking for network interfaces') - ip_address = "" - for interface in netifaces.interfaces(): - if (str(interface) != "lo"): - ip_address += str(netifaces.ifaddresses(interface)[netifaces.AF_INET]) - self.logger.debug('[Registration] returning ip addresses from every interfaces') - return ip_address - """ diff --git a/opt/ahenk/base/system/system.py b/opt/ahenk/base/system/system.py index 772c1a1..6d931bc 100644 --- a/opt/ahenk/base/system/system.py +++ b/opt/ahenk/base/system/system.py @@ -4,6 +4,8 @@ import platform import psutil +import cpuinfo +import re from uuid import getnode as get_mac @@ -143,10 +145,6 @@ class System: class Hardware(object): - @staticmethod - def mac_address(): - return str(':'.join(("%012X" % get_mac())[i:i + 2] for i in range(0, 12, 2))) - class Memory(object): @staticmethod @@ -216,7 +214,18 @@ class System: def ip_addresses(): arr = [] for iface in psutil.net_io_counters(pernic=True): - arr.append(psutil.net_if_addrs()[str(iface)][0][1]) + ip = psutil.net_if_addrs()[str(iface)][0][1] + 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': + arr.append(ip) + return arr + + @staticmethod + def mac_addresses(): + arr = [] + for iface in psutil.net_io_counters(pernic=True): + mac = psutil.net_if_addrs()[str(iface)][2][1] + if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac.lower()) and str(mac) != '00:00:00:00:00:00': + arr.append(mac.lower()) return arr class Cpu(object): @@ -240,3 +249,31 @@ class System: @staticmethod def architecture(): return platform.processor() + + @staticmethod + def vendor(): + return cpuinfo.get_cpu_info()['vendor_id'] + + @staticmethod + def brand(): + return cpuinfo.get_cpu_info()['brand'] + + @staticmethod + def hz_advertised(): + return cpuinfo.get_cpu_info()['hz_advertised'] + + @staticmethod + def hz_actual(): + return cpuinfo.get_cpu_info()['hz_actual'] + + @staticmethod + def bit(): + return cpuinfo.get_cpu_info()['bits'] + + @staticmethod + def family(): + return cpuinfo.get_cpu_info()['family'] + + @staticmethod + def model(): + return cpuinfo.get_cpu_info()['model']