Ver código fonte

Add comments and root check

Added comments to check_port, as well as a check that it's being ran as
root.
ApisNecros 2 anos atrás
pai
commit
b0d2aa7619
1 arquivos alterados com 11 adições e 1 exclusões
  1. 11 1
      check_port

+ 11 - 1
check_port

@@ -1,7 +1,17 @@
 #!/bin/bash
 
+##############
+# Returns the name of the service
+#  running on a given port.
+##############
+
+if [ ! "$UID" = 0 ]; then
+	echo "Must be ran as root"
+	exit 1
+fi
+
 if [ ! "$1" -gt 0 ] || [ ! "$1" -lt 65536 ]; then
 	echo "Port number must be in range 1 - 65535"
-        exit 1
+        exit 2
 fi
 ss -tulpn | grep LISTEN | grep -E ":$1\b" | grep -Po "(?<=\(\(\").+?(?=\")" | uniq