Replace all double quotes strings with single quoted strings.
This commit is contained in:
@@ -2,31 +2,31 @@ def setup_sniff_tcpdump_parser(parser_sniff):
|
||||
# arguments which will be passed to tcpdump
|
||||
parser_sniff_tcpdump = parser_sniff.add_argument_group('tcpdump arguments')
|
||||
# TODO: tcpdump_parser.add_argument('-c', '--count', re)
|
||||
parser_sniff_tcpdump.add_argument("-a", "--ip-address=", help="IP address of the device to sniff", dest="device_ip")
|
||||
parser_sniff_tcpdump.add_argument("-i", "--interface=", help="Interface of the capture device.", dest="capture_interface",default="")
|
||||
parser_sniff_tcpdump.add_argument("-I", "--monitor-mode", help="Put interface into monitor mode",
|
||||
action="store_true")
|
||||
parser_sniff_tcpdump.add_argument("-n", help="Deactivate name resolution. Option is set by default.",
|
||||
action="store_true")
|
||||
parser_sniff_tcpdump.add_argument("-#", "--number",
|
||||
help="Print packet number at beginning of line. Set by default.",
|
||||
action="store_true")
|
||||
parser_sniff_tcpdump.add_argument("-e", help="Print link layer headers. Option is set by default.",
|
||||
action="store_true")
|
||||
parser_sniff_tcpdump.add_argument("-t", action="count", default=0,
|
||||
help="Please see tcpdump manual for details. Unused by default.")
|
||||
parser_sniff_tcpdump.add_argument('-a', '--ip-address=', help='IP address of the device to sniff', dest='device_ip')
|
||||
parser_sniff_tcpdump.add_argument('-i', '--interface=', help='Interface of the capture device.', dest='capture_interface',default='')
|
||||
parser_sniff_tcpdump.add_argument('-I', '--monitor-mode', help='Put interface into monitor mode',
|
||||
action='store_true')
|
||||
parser_sniff_tcpdump.add_argument('-n', help='Deactivate name resolution. Option is set by default.',
|
||||
action='store_true')
|
||||
parser_sniff_tcpdump.add_argument('-#', '--number',
|
||||
help='Print packet number at beginning of line. Set by default.',
|
||||
action='store_true')
|
||||
parser_sniff_tcpdump.add_argument('-e', help='Print link layer headers. Option is set by default.',
|
||||
action='store_true')
|
||||
parser_sniff_tcpdump.add_argument('-t', action='count', default=0,
|
||||
help='Please see tcpdump manual for details. Unused by default.')
|
||||
|
||||
|
||||
def setup_sniff_parser(subparsers):
|
||||
# create parser for "sniff" command
|
||||
parser_sniff = subparsers.add_parser("sniff", help="Start tcpdump capture.")
|
||||
# create parser for 'sniff' command
|
||||
parser_sniff = subparsers.add_parser('sniff', help='Start tcpdump capture.')
|
||||
setup_sniff_tcpdump_parser(parser_sniff)
|
||||
setup_pcap_filter_parser(parser_sniff)
|
||||
cap_size_group = parser_sniff.add_mutually_exclusive_group(required=True)
|
||||
cap_size_group.add_argument("-c", "--count", type=int, help="Number of packets to capture.", default=0)
|
||||
cap_size_group.add_argument("--mins", type=int, help="Time in minutes to capture.", default=60)
|
||||
cap_size_group.add_argument('-c', '--count', type=int, help='Number of packets to capture.', default=0)
|
||||
cap_size_group.add_argument('--mins', type=int, help='Time in minutes to capture.', default=60)
|
||||
|
||||
|
||||
def setup_pcap_filter_parser(parser_sniff):
|
||||
parser_pcap_filter = parser_sniff.add_argument_parser("pcap-filter expression")
|
||||
parser_pcap_filter = parser_sniff.add_argument_parser('pcap-filter expression')
|
||||
pass
|
||||
|
||||
@@ -15,5 +15,5 @@ class Metadata:
|
||||
|
||||
|
||||
def create_metadata(filename, unique_id, device_details):
|
||||
date_string = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
|
||||
meta_filename = f"meta_{date_string}_{unique_id}.json"
|
||||
date_string = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
|
||||
meta_filename = f'meta_{date_string}_{unique_id}.json'
|
||||
|
||||
@@ -8,33 +8,33 @@ from iottb.definitions import DEVICE_METADATA_FILE
|
||||
|
||||
|
||||
def write_device_metadata_to_file(metadata: DeviceMetadata, device_path: Path):
|
||||
"""Write the device metadata to a JSON file in the specified directory."""
|
||||
meta_file_path = device_path / "meta.json"
|
||||
'''Write the device metadata to a JSON file in the specified directory.'''
|
||||
meta_file_path = device_path / 'meta.json'
|
||||
meta_file_path.write_text(metadata.json(indent=2))
|
||||
|
||||
|
||||
def confirm_device_metadata(metadata: DeviceMetadata) -> bool:
|
||||
"""Display device metadata for user confirmation."""
|
||||
'''Display device metadata for user confirmation.'''
|
||||
print(metadata.json(indent=2))
|
||||
return input("Confirm device metadata? (y/n): ").strip().lower() == 'y'
|
||||
return input('Confirm device metadata? (y/n): ').strip().lower() == 'y'
|
||||
|
||||
|
||||
def get_device_metadata_from_user() -> DeviceMetadata:
|
||||
"""Prompt the user to enter device details and return a populated DeviceMetadata object."""
|
||||
device_name = input("Device name: ")
|
||||
device_short_name = device_name.lower().replace(" ", "-")
|
||||
'''Prompt the user to enter device details and return a populated DeviceMetadata object.'''
|
||||
device_name = input('Device name: ')
|
||||
device_short_name = device_name.lower().replace(' ', '-')
|
||||
return DeviceMetadata(device_name=device_name, device_short_name=device_short_name)
|
||||
|
||||
|
||||
def initialize_device_root_dir(device_name: str) -> Path:
|
||||
"""Create and return the path for the device directory."""
|
||||
'''Create and return the path for the device directory.'''
|
||||
device_path = Path.cwd() / device_name
|
||||
device_path.mkdir(exist_ok=True)
|
||||
return device_path
|
||||
|
||||
|
||||
def write_metadata(metadata: BaseModel, device_name: str):
|
||||
"""Write device metadata to a JSON file."""
|
||||
'''Write device metadata to a JSON file.'''
|
||||
meta_path = Path.cwd() / device_name / DEVICE_METADATA_FILE
|
||||
meta_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with meta_path.open('w') as f:
|
||||
@@ -42,7 +42,7 @@ def write_metadata(metadata: BaseModel, device_name: str):
|
||||
|
||||
|
||||
def get_device_metadata(file_path: Path) -> DeviceMetadata | None:
|
||||
"""Fetch device metadata from a JSON file."""
|
||||
'''Fetch device metadata from a JSON file.'''
|
||||
|
||||
if dev_metadata_exists(file_path):
|
||||
with file_path.open('r') as f:
|
||||
@@ -51,10 +51,10 @@ def get_device_metadata(file_path: Path) -> DeviceMetadata | None:
|
||||
device_metadata = DeviceMetadata.from_json(device_metadata_json)
|
||||
return device_metadata
|
||||
except ValueError as e:
|
||||
print(f"Validation error for device metadata: {e}")
|
||||
print(f'Validation error for device metadata: {e}')
|
||||
else:
|
||||
# TODO Decide what to do (e.g. search for file etc)
|
||||
print(f"No device metadata at {file_path}")
|
||||
print(f'No device metadata at {file_path}')
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user