linux see used ports

C++
sudo lsof -i:22netstat -tulpn## if you use linux
sudo ss -tulw

Source

Also in C++: