Port Knocking on macOS Sierra
If you need to get port knocking working as a client (i.e. you want to access a remote service that is protected by port knocking) - then install the knock program from Homebrew like this:

brew install knock


You'll need to have Homebrew installed in advance.

Then you can use the program from Terminal.app like this:

knock myserver 1234 5678 9012


where the numbers are the ports to knock.

If you need to get port knocking working as a server (i.e. you want to protect a local resource so that remote access is limited to those in-the-know by port knocking) - then similarly install knock from Homebrew.

After installation you'll need to create a knockd.conf configuration customized to your requirements (i.e. which type of service you want to protect, the ports to use, etc.) - and finally start knockd using launchd.

You can find an example of how to do this here:

Example knockd setup