Created
December 11, 2025 21:18
-
-
Save jwarwick-bry/1487dea8f452d48a43b2c2d5f6180d9f to your computer and use it in GitHub Desktop.
Scan HTTP-ish ports for SSL/TLS and print certificate expiration dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Scan ports for SSL/TLS and print certificate expiration dates | |
| PORTS=( $(netstat -tuln | grep -oP ':\K[0-9]+' | sort -nu) ) | |
| for port in "${PORTS[@]}"; do | |
| echo -n "Checking port $port... " | |
| result=$(timeout 5 bash -c "echo | openssl s_client -connect 127.0.0.1:$port 2>/dev/null | openssl x509 -noout -enddate 2>/dev/null") | |
| if [[ $result == notAfter* ]]; then | |
| echo "$result" | sed 's/notAfter=/\tExpires: /' | |
| #TODO: parse date and show days remaining, or if expired, output loud warning message to STDERR | |
| sudo lsof -i :${port} -sTCP:LISTEN -nP | awk '{print "\t\t\t",$1,$3,$9}' | |
| else | |
| echo -e "\tNo SSL/TLS detected." | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment