I can get the socket in listen state opened by an user with this code
lsof -sTCP:LISTEN -n -i -P |awk '$3 == "user" { print $0 }'
I would like to now if there is an option to lsof that also filter by user (or by process name by the way). I know that lsof has the -u option but this:
lsof -sTCP:LISTEN -n -i -P -u username
List all the files opened by user username, it doesn't filter the network connections (and it's slow).