Is there any way possible of closing off ports on your pc one by one, instead of having a firewall protecting them ?

Shouldnt is be better, preventing an attack rather than protecting against it.

I mean like telling your pc or OS to not allow example port 27337 to open even though a program wants to open it.

If you know what i mean ?