From 670b84dc4d6e08798ca9febb0fb7acd66a49681c Mon Sep 17 00:00:00 2001 From: Marco Zuppone Date: Wed, 27 Sep 2023 17:57:27 +0100 Subject: [PATCH] Devel (#24) * Changes in decoding the command NO due to FW 1.9a * Version change and minor fixes * Minor comments fixes --------- Co-authored-by: Marco Simone Zuppone --- README.md | 8 ++++---- pressureTest.py | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 4ec5a9e..737c836 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ # PayShieldPressureTest - +logo of Python Foundation Supporting Member The **pressureTest.py** Python script creates a workload on the **Thales payShield 10k** and **9k** appliances. The script can be useful during demonstrations of the monitoring features of the appliance and can be used in every case you need to generate a workload for testing purposes. -It requires **Python 3**. It was tested on **Python 3.10.2** using a **payShield 10k** with firmware **1.7**. +It requires **Python 3**. It was tested on **Python 3.10.2** using a **payShield 10k** with firmware **1.7a**. ## Version -**1.3** +**1.3.1** ## Usage @@ -103,7 +103,7 @@ The possible choices are: C:\Test>python pressureTest.py 192.168.0.36 --nc --times 2 - PayShield stress utility, version 1.3, by Marco S. Zuppone - msz@msz.eu - https://msz.eu + PayShield stress utility, version 1.3.1, by Marco S. Zuppone - msz@msz.eu - https://msz.eu To get more info about the usage invoke it with the -h option This software is open source, and it is under the Affero AGPL 3.0 license diff --git a/pressureTest.py b/pressureTest.py index 4f26243..1e0f0b7 100644 --- a/pressureTest.py +++ b/pressureTest.py @@ -14,7 +14,7 @@ from typing import Tuple, Dict from types import FunctionType -VERSION = "1.3" +VERSION = "1.3.1" class PayConnector: @@ -233,13 +233,18 @@ def decode_no(response_to_decode: bytes, head_len: int): str_pointer = str_pointer + 1 print("Type of connection: ", NET_PROTO.get(response_to_decode[str_pointer:str_pointer + 1], "Unknown")) str_pointer = str_pointer + 1 - print("Number of TCP sockets: ", response_to_decode[str_pointer:str_pointer + 2]) - str_pointer = str_pointer + 2 + if len(response_to_decode) > (24 + head_len): # FW 1.8a or more + socket_field_len = 4 # From FW 1.8a the Number of TCP sockets is 4 character long instead of 2 + else: + socket_field_len = 2 + print("Number of TCP sockets: ", response_to_decode[str_pointer:str_pointer + socket_field_len]) + str_pointer = str_pointer + socket_field_len print("Firmware number: ", response_to_decode[str_pointer:str_pointer + 9]) str_pointer = str_pointer + 9 print("Reserved: ", response_to_decode[str_pointer:str_pointer + 1]) str_pointer = str_pointer + 1 print("Reserved: ", response_to_decode[str_pointer:str_pointer + 4]) + else: # Mode 01 str_pointer = str_pointer + 2 if response_to_decode[str_pointer:str_pointer + 1] == '0': @@ -1003,8 +1008,8 @@ def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, i parser = argparse.ArgumentParser( description="Generates workload on PayShield 10k and 9k for the sake of testing and demonstration.", - epilog="For any questions, feedback, suggestions or send money (yes...it's a dream, I know), you can contact the " - "author at msz@msz.eu") + epilog="For any questions, feedback, suggestions or send money (yes...it's a dream, I know), you can contact " + "the author at msz@msz.eu") parser.add_argument("host", help="Ip address or hostname of the payShield") group = parser.add_mutually_exclusive_group() parser.add_argument("--port", "-p", help="The host port. " @@ -1050,7 +1055,6 @@ def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, i parser.add_argument("--decode", help="If specified the reply of the payShield is interpreted " "if a decoder function for that command has been implemented.", action="store_true") - parser.add_argument("--times", help="How many times to repeat the operation " "If not specified the default is 1000.", type=int, default=1000) parser.add_argument("--proto", help="Accepted values are tcp, udp or tls. The default is tcp", default="tcp",