Batch add firewall exception ports in Windows

Source: Internet
Author: User

Batch add firewall exception ports in Windows

Copy codeThe Code is as follows: echo off
Cls
Set var = 30000
Set end = 30010
: Continue
Set/a var + = 1
Echo add port % var %
Netsh firewall add portopening TCP % var % ftp_data _ % var %
If % var % lss % end % goto continue
Echo complete
Pause

The following article highlights that you can manually add them in order or batch output them through batch processing such as vbs js.
For example, the following ports are 80, 3389, 4399,3001-3020 ....
It is more convenient to output arrays in batches, that is, the following code.

An easy way to add ports to exceptions in batches using the firewall provided by the XP System

Today, a software is installed on a computer, and dozens of ports need to be added to the firewall. it turns out that only one of them can be added. VBS is used for batch addition. I have never learned VBS and can't use it, so I had to think of using the old friend bat file. the result shows that it is really good. We can write down the method for future use.
The statement for adding a port to the firewall in bat is as follows:
Netsh firewall set portopening udp/tcp/all port_number name enable
Therefore, in order to save time and energy, first create an excel file and write the statements to be added, such:

Here, I name the port polycom-port number, select all records, and copy them to the text document. and delete the TAB character in the middle of the name. this step is easy, just to save some effort. if it is not too troublesome, you can write it all into the text document. However, if there are too many ports, the workload is not small.
Save the text document as a bat file. The content is as follows:Copy codeThe Code is as follows: @ echo off
Add the port number to be added to the exception under rem. Use all here to indicate TCP and UDP. If it is only tcp or UDP, you can change it to the appropriate one.
Netsh firewall set portopening all 3230 polycom-3230 enable
Netsh firewall set portopening all 3231 polycom-3231 enable
Netsh firewall set portopening all 3232 polycom-3232 enable
Netsh firewall set portopening all 3233 polycom-3233 enable
Netsh firewall set portopening all 3234 polycom-3234 enable
Netsh firewall set portopening all 3235 polycom-3235 enable
Netsh firewall set portopening all 3236 polycom-3236 enable
Netsh firewall set portopening all 3237 polycom-3237 enable
Netsh firewall set portopening all 3238 polycom-3238 enable
Netsh firewall set portopening all 3239 polycom-3239 enable
Netsh firewall set portopening all 3240 polycom-3240 enable
Netsh firewall set portopening all 3241 polycom-3241 enable
Netsh firewall set portopening all 3242 polycom-3242 enable
Netsh firewall set portopening all 3243 polycom-3243 enable
Netsh firewall set portopening all 3244 polycom-3244 enable
Netsh firewall set portopening all 3245 polycom-3245 enable
Netsh firewall set portopening all 3246 polycom-3246 enable
Exit

Save it as a bat file. Here I will save it as a polycom_port_add.bat file.
In this way, the execution of this file is complete.
The deletion method is also very simple. Make a backup and rename the file. Here I will change it to polycom_port_del.bat.
Then modify the content and replace the set with delete (do not tell me who will not replace it). Then replace the name and enable with spaces. The content is as follows:
Netsh firewall delete portopening all 3230
........
If you want to delete these ports, you can use them directly.

In fact, the method is really too simple, it only consumes physical strength, so I decided to use excel, and can use word (word can easily replace special symbols such as tabs). This is much easier.
I have a smile.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.