This can be useful when you don't want people to map out your device and see what you're running and not, so it's a small step to defeat reconnaissance.
Portforge uses a technique built-in the Crystal compiler called Fibers. They are very much like system threads but Fibers is a lot more lightweight & the execution is managed through the process 1.
The larger range you pick, the longer it takes for the script to load up every socket but I've tried my best to optimize the script so it should just take a couple of minutes (depending on the system of course).
The script works in 2 steps: It first performs its own scan on the system to see which port is already open. The open ports is then put on one list and the closed ports are put on another list. The next step is opening the closed ports, so the script picks the list with all the closed ports and opens a socket on every one of them.
While the main fiber is opening a socket on every port, another fiber is called under the main one which listens for incoming connections and closes it directly. This process is repeated indefinitely, or until you interrupt the script.
./portforge IP startport endport