System and Network Tools Flashcards

socket, platform, os and psutil (34 cards)

1
Q

Define Network Interface Cards (NIC)

A

hardware components allowing communication between network and machine

they implement physical and datalink layers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Most modern machines come with several NICs like

A

wireless, ethernet and bluetooth
virtual nics if VPN or VM is used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What address do NIC cards have

A

48-bit (12 hex) MAC address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

However, since a NIC can have several virtual
interfaces, the OS needs other methods to identify these interfaces. On Windows, there
are four methods:

A

UUID (128-bits) (32 hex)

Name <type>_<index>
type like ethernet or wireless</index></type>

Friendly Name easier to remember than name

Description

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

On Windows 11, you can get full information about the system’s NICs through

what about unix?

A

SI -> C -> N -> Adapter
or
ipconfig /all

lshw or ip commands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

This function is used to get a list of NICs, both physical and virtual, for the underlying
device.

A

socket.if_nameindex()

list of tuples (index, name)

If fails OSError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

If you have a NIC name and you want the index, then you can use the following function:

To do the reverse index and get NIC name?

A

socket.if_nametoindex(nic_name)

socket.if_indextoname(index)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define The platform Module

A

built-in python modules provides various system information about platform in which python is running

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

platform modules is defined under what category

A

generic os services

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

relevant platform functions

A

architecture()
machine()
processor()
node()
system()
platform()
win32_ver()
python_version()
python_implementation()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what does architecture () return

A

bits and linkage format

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what does node () return

A

hostname
same as
socket.gethostname()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what does system() return

A

operating system

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does platform return

A

a single string representing the underlying platform

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what does win32_ver() return

A

a tuple that contains some information about the windows system like release and version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what does python_version() return

A

a string with the version

17
Q

The os module in Python is a very large module that contains a large number of functions
to perform:

A

Miscellaneous operating system interfaces

18
Q

relevant os module functions

A

environ —-not function
getenv(key)
putenv(key)
getlogin()
listdrives()
stat(path)
system(command)
cpu_count()

19
Q

What does environ do?

A

displays environment variables in the system

-> returns a mapping object where the key is a string of variable and the value is a string for its corresponding value.

20
Q

what does getenv(key) do?

A

return the environment variable value for the key

21
Q

what does putenv(key,val)

A

sets environment variable key to the value

22
Q

getlogin() function

A

returns the name of the user logged in

whoami

23
Q

what does listdrives() return

A

a list of the drives on a windows system

fsutil fsinfo drives in cmd

24
Q

what does stat(path) return

A

information about a file

like file size, creation time

25
os. system(command) does?
executes command in a subshell
26
The Python System Library (psutil) Module does/purpose/definition
provides rich list of functions that can be used to collect system information not a part of built-in standard python libraries ==> pip install psutil
27
description of some important functions defined in the psutil module:
net_if_addrs() disk_partitions() cpu_count(logical) virtual_memory() disk_usage(path) net_connections() sensors_battery() users() pids() net_if_addrs net_connections disk_usage disk_partitions users pids cpu_count sensors_battery virtual memory
28
what does net_if_addrs() return
returns a dictionary of addresses associated with each NIC key is NIC friendly name and value is a tuple of (MAC, ipv4, ipv6, +)
29
what does disk_paritions() return
number of disk partitions list of named tuples
30
what does virtual_memory() return
returns a named tuple statistics about the memory like size of physical memory (RAM) used space free space
31
disk_usage(path) return shit
returns a named tuple consisting of disk space statistics of the given path e.g. total space, available space, used space
32
what does users() return
list of named tuples, each containing information about currently connected users
33
what does net_connections() return
Return a list of named tuples of system-wide socket connections
34
what does pids() return
Returns a sorted list of current running PIDs