-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram_launcher.py
More file actions
41 lines (32 loc) · 1.2 KB
/
program_launcher.py
File metadata and controls
41 lines (32 loc) · 1.2 KB
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
"""
This module contains the program launcher functions.
"""
import subprocess
from enum import Enum
class ICommand(str, Enum):
"""Interface for program commands."""
class ArpScanCommands(ICommand):
"""Commands to get connected MAC addresses using ArpScan."""
GET_VERSION_INFO = "sudo arp-scan --version"
INSTALL_PROGRAM = "sudo apt-get install arp-scan"
GET_CONNECTED_MAC_ADDRESSES = "sudo arp-scan --localnet "\
"| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'"
GET_CONNECTED_IP_ADDRESSES = "sudo arp-scan --localnet "\
"| grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}'"
class PingCommands(ICommand):
"""Commands to send a ping to a device using ping."""
GET_VERSION_INFO = "ping --version"
INSTALL_PROGRAM = "sudo apt-get install iputils-ping"
PING_TO = "ping -c 1"
def run_program(command: ICommand) -> str:
"""This method runs a program and returns the output and error."""
output, error = subprocess.Popen(
command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
).communicate()
# Check if there was an error.
if error:
raise RuntimeError(error)
return output.decode('utf-8')