mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-25 11:12:15 +03:00
mac addresses and ip addresses format validation, new info serving about processor
This commit is contained in:
parent
c72785c53a
commit
37ec0551a9
2 changed files with 47 additions and 31 deletions
|
@ -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
|
||||
"""
|
||||
|
|
|
@ -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']
|
||||
|
|
Loading…
Reference in a new issue