Skip to content

Commit 10a0309

Browse files
authored
Merge pull request #20 from mszeu/devel
Devel to Masster
2 parents 925fee1 + e1aa9b8 commit 10a0309

File tree

2 files changed

+11
-37
lines changed

2 files changed

+11
-37
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,4 +658,4 @@ specific requirements.
658658
You should also get your employer (if you work as a programmer) or school,
659659
if any, to sign a "copyright disclaimer" for the program, if necessary.
660660
For more information on this, and how to apply and follow the GNU AGPL, see
661-
<https://www.gnu.org/licenses/>.
661+
<https://www.gnu.org/licenses/>.

pressureTest.py

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from typing import Tuple, Dict
1414
from types import FunctionType
1515

16-
VERSION = "1.1.7"
16+
VERSION = "1.1.7.2"
1717

1818

1919
def decode_n0(response_to_decode: bytes, head_len: int):
@@ -56,7 +56,7 @@ def decode_no(response_to_decode: bytes, head_len: int):
5656
"""
5757
BUFFER_SIZE: Dict[str, str] = {
5858
'0': '2K bytes', '1': '8K bytes', '2': '16K bytes', '3': '32K bytes'}
59-
NET_PROTO: Dict[str, str] = {'0': 'TCP', '1': 'UDP'}
59+
NET_PROTO: Dict[str, str] = {'0': 'UDP', '1': 'TCP'}
6060
response_to_decode, msg_len, str_pointer = common_parser(response_to_decode, head_len)
6161
if response_to_decode[str_pointer:str_pointer + 2] == '00': # No errors
6262
if len(response_to_decode) >= (24 + head_len): # Mode 00
@@ -125,8 +125,8 @@ def decode_ni(response_to_decode: bytes, head_len: int):
125125
str_pointer = str_pointer + 8
126126
print("Remote port number: ", response_to_decode[str_pointer:str_pointer + 4])
127127
str_pointer = str_pointer + 4
128-
print("Connection Status: ", NET_CONNECTION_STATUS.get(response_to_decode[str_pointer:str_pointer + 1]
129-
, 'Reserved'))
128+
print("Connection Status: ", NET_CONNECTION_STATUS.get(response_to_decode[str_pointer:str_pointer + 1],
129+
'Reserved'))
130130
str_pointer = str_pointer + 1
131131
print("Duration: ", response_to_decode[str_pointer:str_pointer + 8])
132132
str_pointer = str_pointer + 8
@@ -729,7 +729,7 @@ def run_test(ip_addr: str, port: int, host_command: str, proto: str = "tcp", hea
729729
if proto not in ['tcp', 'udp', 'tls']:
730730
print("invalid protocol parameter, It needs to be tcp, udp or tls")
731731
return -1
732-
732+
connection = None
733733
try:
734734

735735
# calculate the size and format it correctly
@@ -796,18 +796,16 @@ def run_test(ip_addr: str, port: int, host_command: str, proto: str = "tcp", hea
796796
decoder_funct(data, header_len)
797797

798798
except ConnectionError as e:
799-
print("Connection issue: ", e.message)
799+
print("Connection issue: ", e)
800800
except FileNotFoundError as e:
801801
print("The client certificate file or the client key file cannot be found or accessed.\n" +
802-
"Check value passed to the parameters --keyfile and --crtfile", e.message)
802+
"Check value passed to the parameters --keyfile and --crtfile", e)
803803
except Exception as e:
804-
if hasattr(e, 'message'):
805-
print("Unexpected issue:", e.message)
806-
else:
807-
print("Unexpected issue:", e)
804+
print("Unexpected issue:", e)
808805

809806
finally:
810-
connection.close()
807+
if connection is not None:
808+
connection.close()
811809

812810

813811
def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, int]:
@@ -1016,27 +1014,3 @@ def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, i
10161014
run_test(args.host, args.port, command, args.proto, len(args.header), None)
10171015
print("")
10181016
print("DONE")
1019-
1020-
1021-
def setup_connection(ip_addr: str, port: int, proto: str = "tcp") -> socket:
1022-
if proto == "tcp":
1023-
# creates the TCP socket
1024-
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1025-
connection.connect((ip_addr, port))
1026-
return connection
1027-
1028-
elif proto == "tls":
1029-
# creates the TCP TLS socket
1030-
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1031-
ciphers = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:AES128-GCM-SHA256:AES128-SHA256:HIGH:"
1032-
ciphers += "!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK"
1033-
ssl_sock = ssl.wrap_socket(connection, args.keyfile, args.crtfile)
1034-
ssl_sock.connect((ip_addr, port))
1035-
return connection
1036-
1037-
elif proto == "udp":
1038-
# create the UDP socket
1039-
connection = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
1040-
return connection
1041-
1042-
return None

0 commit comments

Comments
 (0)