Skip to main content

Check for open ports in Windows


How to check which ports are open?

How to check the ports that a particular application is using?

Questions that will pop up when things go wrong, when an application does not work as expected.

When replication does not work, or access denied error occurs.

Or when an error occurs that states, a particular port is in use. Like, Port 80 is in use.

Of course the error, just gives an idea that a port is in use by another application or program but does not explicitly tells that which specific application or program is using the port.

This is where troubleshooting is necessary. An example below is given.

One scenario that I can think of is when setting up Active Directory replication; whether in the real world, or in a test lab environment.

Or even simply a port forwarding scenario on web hosting, CCTV installation or other setup,  if it doesn’t work would require troubleshooting or to check whether ports are open, ports are listening or not.

Netstat command in Windows is a good start to check or start troubleshooting and using Netstat 
parameters, will be able to check ports that are open and which application is using the port.

There is also one good tool provided by Sysinternals, called TCPView that provides comprehensive output on ports troubleshooting.

Nmap is also a good tool, which has been a familiar tool on the Linux world.

But Nmap got a package for Windows operating system also.

Typing “netstat /?” in Windows command prompt will show the available parameters for netstat.

Typing “netstat –ano”, (don’t include quotes when typing on the command prompt). This will show the protocol being used by the port and also the PID (process ID number) of the application that is using the port.

Task Manager can be sued to view the PID or process id number.

Or if you are using Windows 7 or above OS version, PowerShell can easily check the process ID or PID number.

Open PowerShell ISE and type get-process –id “PID” number that you want to query.

Example below shows that the “netstat” output has a PID number of 3836 and the connection is established using TCP protocol. Port being used is 49316 and 40003

C:\Windows\System32>netstat -ano
Active Connections
  Proto    Local Address              Foreign Address           
  TCP    192.168.1.8:49316      192.168.74.24:40003   

  State                          PID
  ESTABLISHED    3836

And the PID number can be viewed using PowerShell, to check which application is using the particular PID number.

Get-process -id "3836"

Example output:
Handles  NPM(K)    PM(K)      WS(K)    VM(M)      CPU(s)                                           
-------       ------          -----            -----             -----          ------             
   1289     147         189248     199684        549 1,    414.26   

 Id       ProcessName                     
  --       -----------   
  3836  Skype                                                                                                                        

Above example, is checking from inside the local network. But if your application goes outside the local network or need WAN connectivity. Then a different approach of checking the ports whether they are open or not.

And for WAN connectivity to open ports will involve configuring router, firewall or other setup and solely depends on the network infrastructure. You can search the web for “Port Forwarding Configuration”, but don’t open ports for the sake of opening ports without any reason or just for fun.

Make sure you know exactly what you are doing, open ports on your system are great, great opportunity for others to manipulate and abused your system.

Dyn website provide a very good tool to check open or closed ports:


To use this tool need to have a Dyn account.

Well, these are just network basic stuff and hope it helps someone.

The methods above can be used also, to check what  application or process is using the port.


  

Comments

Popular posts from this blog

Copy a single file using robocopy

Copy a single file using robocopy from a local folder to a shared folder on the network.
A simple rule of thumb before any disaster strike, don't interchange the source and the destination.

If source and destination is mistakenly reverse, files might get overwritten. To avoid any loss of data do a test with a dummy file to ensure things work perfectly.
Robocopy [source][destination]   [file to be copied]
robocopy c:\local_c_folder  \\PC_network\shared_folder   file_to_be_copied_xx.txt
The command will be completed successfully provided the network access right has no issues.

Robocopy works quite good on large files. A simple copy or xcopy command will also work but the speed might vary.

Robocopy is free it can be accessed from command line. No need to install the resource kit tool if the operating system is Windows 7 or newer version.

Copy files with selected file extension using PowerShell and Robocopy:

$extension = ('.pdf', '.jpg', '.txt')
gci d:\WorkFolde…

WMIC get computer name

WMIC get computer model, manufacturer, computer name and  username.
WMIC is a command-line tool and that can generate information about computer model, its manufacturer, its username and other informations depending on the parameters provided.
Why would you need a command line tool if there’s a GUI to check?
If you have 20 or 100 computers, or even more. It’s quite a big task just checking the GUI to check the computer model and username.
If you have remote computers, you need to delegate someone in the remote office or location to check.
Or you can just write a batch file or script to automate the task.
Here’s the code below on how get computer model, manufacturer and the username.
Open an elevated command prompt and type:
wmic computersystem get "Model","Manufacturer", "Name", "UserName"
Just copy and paste the code above, the word “computersystem” does not need to be change to a computer name.
A sample output below will be generated if the co…