-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyutils.py
58 lines (44 loc) · 1.38 KB
/
pyutils.py
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
54
55
56
57
58
"""
Utility methods and helper methods used around the project.
"""
import datetime
import time
from pathlib import Path
from scapy.packet import Packet
def get_timestamp():
"""Gets a current timestamp with a global format."""
# Create a timestamp
timestamp = time.time()
# Format the timestamp
timestamp = datetime.datetime.fromtimestamp(timestamp).strftime(
'%H:%M:%S')
return timestamp
def extract_hook_name(filepath):
# if not check_file_exists(filepath):
# return # Maybe raise error
pre_hook_name = filepath.split('/')
hook_name = pre_hook_name[-1]
hook_name = hook_name[:-3]
print("Extracted hook {}".format(hook_name))
return hook_name
def check_file_exists(filepath):
"""Checks if the file exists."""
# print("Checking if filepath {} is a file".format(filepath))
filepath = "{}".format(filepath)
fl = Path(filepath)
if fl.is_file():
return True
return False
def create_packet(binary_packet):
"""Loads a packet to be sent via subprocess."""
return Packet(binary_packet)
def load_packet(binary_packet):
"""Loads a packet to be sent via subprocess."""
pkt = Packet(binary_packet)
pkt = str(pkt.payload)
return pkt
def unload_packet(string_packet):
"""Unloads packet to be read after subprocess."""
return Packet(string_packet)
def retreive_packet():
pass