Last active
November 8, 2016 13:17
-
-
Save avescodes/a241a287f0bab43fba1e to your computer and use it in GitHub Desktop.
Updates to itg's ports.sh (http://itsthatguy.com/post/74083110644/alfred-workflow-list-currently-listening-tcp-ports)
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
#!/usr/bin/env bash | |
pattern=$1 | |
PORTS="" | |
if [ -z "$pattern" ]; then | |
PORTS=$(lsof -iTCP -sTCP:LISTEN) | |
else | |
PORTS=$(lsof -iTCP -sTCP:LISTEN | grep "$pattern") | |
fi | |
i=0 | |
echo "<?xml version='1.0'?><items>" | |
while read -r line; do | |
if [ $i -gt 0 ]; then | |
x=($line) | |
boop=$(cut -d ":" -f 2 <<< "${x[8]}") | |
echo "<item uid='${x[1]}' arg='' valid='yes'> | |
<title>${x[0]}: ${boop}</title> | |
<subtitle>PID: ${x[1]}</subtitle> | |
<icon>icon_port.png</icon> | |
</item>" | |
fi | |
((i++)) | |
done <<<"$PORTS" | |
echo '</items>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment