Lets say you want to check if port 1234 is open, run the following command in the terminal. nmap is not available on mac osx by default.You can install it with Homebrew, my preferred package manager for mac osx. Visit homebrew site for instructions on Homebrew installation.
nmap -p 1234 localhost
This will output the status ..
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).
PORT STATE SERVICE
1234/tcp closed ppp
To open this port, add the following line in /etc/pf.conf
sudo vim /etc/pf.conf
# Open port 1234 for TCP on all interfaces
pass in proto tcp from any to any port 1234
# You can limit the ip addresses .. replace any with allowed addresses ..
Save the file.
I restarted my mac and once I had the application running at port 1234, the status reported by nmap command (mentioned above) changed to ‘open’ and I was able to use my mac’s ip and port to access the application from another computer.
You can also use Network Utility – Port Scan to scan for open ports on your mac.