From deec9693149dab66a889f89889874988fa489a54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20De=20Keersmaeker?=
 <francois.dekeersmaeker@uclouvain.be>
Date: Thu, 11 May 2023 23:37:04 +0200
Subject: [PATCH] Updated argument order

---
 README.md           |  4 ++--
 src/pcap_tweaker.py | 19 ++++++++++++-------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 234d1ea..ee61eff 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ pip install -r requirements.txt
 ## Usage
 
 ```bash
-python3 pcap_tweaker.py [-h] [-d] [-r RANDOM_RANGE] [-n PACKET_NUMBER] pcap [pcap ...]
+python3 pcap_tweaker.py [-h] [-r RANDOM_RANGE] [-n PACKET_NUMBER] [-d] pcap [pcap ...]
 ```
 
 The program produces new PCAP file with the same name as the input files,
@@ -44,9 +44,9 @@ It will be created if it doesn't exist.
 ### Optional arguments
 
 * `-h`, `--help`: show help message and exit
-* `-d`, `--dry-run`: don't write the output PCAP file (but still write the CSV log file)
 * `-r`, `--random-range`: upper bound for the random range, which will select for each packet if it will be edited or not. In practice, each packet will be edited with a probability of `1/r`. Must be a strictly positive integer. Default: `1` (edit all packets).
 * `-n`, `--packet-number`: index of the packet to edit, starting from 1. Can be specified multiple times. If this is used, only the specified packets will be edited, and no random editing will be performed.
+* `-d`, `--dry-run`: don't write the output PCAP file (but still write the CSV log file)
 
 
 ## Supported protocols
diff --git a/src/pcap_tweaker.py b/src/pcap_tweaker.py
index a52a834..ce38aaa 100644
--- a/src/pcap_tweaker.py
+++ b/src/pcap_tweaker.py
@@ -31,15 +31,15 @@ def strictly_positive_int(value: any) -> int:
         return ivalue
 
 
-def tweak_pcaps(pcaps: list, dry_run: bool, packet_numbers: list, random_range: int = 1) -> None:
+def tweak_pcaps(pcaps: list, random_range: int = 1, packet_numbers: list = None, dry_run: bool = False) -> None:
     """
     Main functionality of the program:
     (Randomly) edit packet fields in a (list of) PCAP file(s).
 
     :param pcaps: list of input PCAP files
-    :param dry_run: if True, do not write output PCAP file
-    :param packet_numbers: list of packet numbers to edit (starting from 1)
     :param random_range: upper bound for random range (not included)
+    :param packet_numbers: list of packet numbers to edit (starting from 1)
+    :param dry_run: if True, do not write output PCAP file
     """
     
     # Loop on given input PCAP files
@@ -129,18 +129,23 @@ if __name__ == "__main__":
     )
     # Positional arguments: input PCAP file
     parser.add_argument("input_pcaps", metavar="pcap", type=str, nargs="+", help="Input PCAP files.")
-    # Optional flag: -d / --dry-run
-    parser.add_argument("-d", "--dry-run", action="store_true",
-                        help="Dry run: do not write output PCAP file.")
     # Optional flag: -r / --random-range
     parser.add_argument("-r", "--random-range", type=strictly_positive_int, default=1,
                         help="Upper bound for random range (not included). Must be a strictly positive integer. Default: 1 (edit each packet).")
     # Optional flag: -n / --packet-number
     parser.add_argument("-n", "--packet-number", type=int, action="append",
                         help="Index of the packet to edit, starting form 1. Can be specifed multiple times.")
+    # Optional flag: -d / --dry-run
+    parser.add_argument("-d", "--dry-run", action="store_true",
+                        help="Dry run: do not write output PCAP file.")
     # Parse arguments
     args = parser.parse_args()
 
 
     ### MAIN PROGRAM ###
-    tweak_pcaps(args.input_pcaps, args.dry_run, args.packet_number, args.random_range)    
+    tweak_pcaps(
+        pcaps=args.input_pcaps,
+        random_range=args.random_range,
+        packet_numbers=args.packet_number,
+        dry_run=args.dry_run
+    )
-- 
GitLab