Google is your friend: you've asked more than enough questions by know to know to try it first.
A trivial google using part of your question gives loads of info on how to do it:
add programmatically Firewall rule - Google Search[
^]
In future, please try to do at least basic research yourself, instead of wasting your time and ours...