Python Loop over List and swap elements

Posted by Scratches on June 25, 2023
To get a list of all listening TCP ports with lsof type:

sudo lsof -nP -iTCP -sTCP:LISTEN
Copy
The options used are as follows:

-n - Do not convert port numbers to port names.
-p - Do not resolve hostnames, show numerical addresses.
-iTCP -sTCP:LISTEN - Show only network files with TCP state LISTEN.