Link to home
Start Free TrialLog in
Avatar of robinyanwang
robinyanwang

asked on

how to open/close ports using DOS command

I know netstat to check current ports using in my workstation, but I do not know which command to control these ports?
Can anyone help? thanks/

-S
ASKER CERTIFIED SOLUTION
Avatar of Bob Lamberson
Bob Lamberson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rob Williams
There are a series of commands. For example to open a port:
   netsh firewall add portopening TCP 80 HTTP enable subnet
Where service is HTTP, Port is 80, Protocol is TCP and allowed scope is the subnet

Some useful articles
A general overview:
http://www.windowsnetworking.com/articles_tutorials/Using-Netsh-Windows-Firewall.html

Condensed instruction/syntax:
http://www.jsifaq.com/SUBP/tip7900/rh7908.htm

Very detailed instructions starting on page 37 of the following Microsoft document:
http://download.microsoft.com/download/6/8/a/68a81446-cd73-4a61-8665-8a67781ac4e8/wf_xpsp2.doc
Avatar of rich255
rich255

Open ports are associated with services running on your PC.  You need to find out what service uses that port, then shut off that service using the Services administrative tool, or by shutting down the third party application that opens the port.

Netstat -an will show you your "listening" ports... the ones opened by services and apps.

C:\>netstat -an

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:21             0.0.0.0:0              LISTENING
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING
  TCP    0.0.0.0:1025           0.0.0.0:0              LISTENING
  TCP    0.0.0.0:3389           0.0.0.0:0              LISTENING

rich
robinyanwang, your question was "how to open/close ports using DOS command........I do not know which command to control these ports?"

I don't understand how the answer you accepted, using netstat, answers your question of how to open or close ports. Netstat, as you yourself stated, simply displays protocol statistics.  Future readers look to the accepted answer as a solution. Selecting an incorrect answer is misleading for them. You may wish to; re-open the question, change the awarded points, or if no answer is acceptable, ask to have the question closed. You can do so by posting a question in the community support page.
Thanks,
--Rob
Well, here's a problem that I'm having:

When I use

netsh firewall delete portopening tcp XXX
or even
netsh firewall add portopening tcp blab lbabl ablab

and then I use the netstat utility to view the open ports, I still see the one (that I closed) listed.

Example:
>netsh firewall add portopening tcp 91 randomport
>netstat -a|find /n /i "91"

>

But when I open the windows firewall GUI, I see the port that I added. (it's just not reflected by netstat).  Arg.

I also agree (respectifully) with RobWill re:the accepted solution.