List which processes opened a port

Murus
Post Reply
RamonManuel
Posts: 9
Joined: Tue Apr 05, 2016 6:24 am

List which processes opened a port

Post by RamonManuel » Mon Apr 11, 2016 6:41 am

Aloha,

It would be very good to know which process opened ports. Especially when a service was automatically created and managed by Murus Unmanaged Open Ports System.

Right now I have to go to the terminal and enter, for example, "lsof -n -i:1790 | grep LISTEN" to see who opened port 1790.

Thanks,

Ramón

hany
Posts: 445
Joined: Wed Dec 10, 2014 5:20 pm

Re: List which processes opened a port

Post by hany » Mon Apr 11, 2016 10:34 pm

nice idea, I like it :)
if I add this feature and send you a beta will you help me testing and debugging it? :)

RamonManuel
Posts: 9
Joined: Tue Apr 05, 2016 6:24 am

Re: List which processes opened a port

Post by RamonManuel » Thu Apr 14, 2016 8:33 pm

I would love to test it!

This is my hack to see who has ports open(displayed on my desktop with Geektool):

Code: Select all

#!/bin/bash
# needs GNU sed (installed, in my case, with homebrew)

name () { 
	mypath=`ps -p $1 -o comm= |sed "s/\.app.*//"`
	basename "$mypath" \
	| sed "s/  */•/g" \
	| sed "s/.*com.agilebits.onepassword-osx-helper/1Password/" \
	| sed "s/\[.*\.\([^\.]*\)\]/(\1)/"
}
export -f name

echo -e "$Open User Ports"

lsof -P -iTCP -sTCP:LISTEN | awk '{print $2, $9}' \
| tail -n +2 \
| sed "s/ .*:/ /g" \
| uniq \
| /usr/local/bin/sed -n 's/\(^[0-9][0-9]*\)/echo "$(name \1)"/ep' \
| awk -v OFS=' ' '{x=$1;$1="";a[x]=a[x]$0}END{for(x in a)print x,a[x]}' \
| sort -u -b | column -t \
| sed "s/•/ /g"

hany
Posts: 445
Joined: Wed Dec 10, 2014 5:20 pm

Re: List which processes opened a port

Post by hany » Fri Apr 15, 2016 1:07 pm

This is my hack to see who has ports open(displayed on my desktop with Geektool):
Thanks a lot, this is really cool and helpful :)
I'll let you have news asap :)

Post Reply