From 686ae00927fb2cb66da537f12c6fc7f634539d9d Mon Sep 17 00:00:00 2001 From: Henry Martinez <7996045+martinezhenry@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:36:49 -0500 Subject: [PATCH] adding available-port.py --- available-port.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 available-port.py diff --git a/available-port.py b/available-port.py new file mode 100644 index 0000000..62b683b --- /dev/null +++ b/available-port.py @@ -0,0 +1,32 @@ +import os +import sys + + +# Def function log +# print a new line to debug + + +def log(msg): + print(print_prefix + msg) + + +args = sys.argv +port = '' +print_prefix = "-> " +if len(args) > 1: + port = args[1] +else: + log("please indicate a port") + log("ex: python available-port.py {port-number}") + log("{port-number} must be replaced with de port number what you want to check") + exit(0) + +log("checking port: " + port) +stream = os.popen('netstat -lntu | grep :' + port + ' | awk \'{print $6}\'') +output = stream.read() + +if len(output) > 0: + log("status: " + output) +else: + log("port " + port + " is not listening") +