Added comments to check_port, as well as a check that it's being ran as root.
@@ -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