Check if a port is being used on a Windows machine

August 8th, 2007   20 Comments

To check if a port is currently in use on a Windows machine, and then get some clue as to what’s using it, run the netstat program from a command console.

  1. Start > Run
  2. Enter cmd
  3. In the command console enter:
    netstat -ano|grep portNumber
    This lists any processes where the port number is included somewhere on the line.
  4. Look at the first number (in the second column). If this shows the port number after a colon, this means the port is currently being used.
  5. Make a note of the number at the end of the line. This is the process ID (PID).
  6. Run the ps program and grep for this PID:
    ps -ef|grep PID

Example

Here I was checking what was using port 4485.

C:\Documents and Settings\Administrator>netstat -ano|grep 4485
  TCP    192.100.61.161:4485    66.249.91.103:80       CLOSE_WAIT      2444

C:\Documents and Settings\Administrator>ps -ef|grep 2444
 Administrator 2444    – -   Aug 02   -   0:16 GoogleDesktopIndex      3    5

It turned out GoogleDesktopIndex was using that port. 

Potentially similar posts

Comments are closed

  1. User Gravatar dpsguard said:

    July 11th, 2009 at 8:44 pm (#)

    Hi,

    Grep is not supported in windows?

    C:\>netstat -ano|grep 4485
    ‘grep’ is not recognized as an internal or external command,
    operable program or batch file.

    Am I missing something?

    Thanks

  2. User Gravatar Alistair said:

    July 12th, 2009 at 12:31 am (#)

    All I can say is: it is for me. I’m using Windows Vista Ultimate. I just opened a command console and did:

    C:\Windows\system32>grep
    usage: grep [-abcEFGHhIiLlnoPqRrSsUvwx] [-A num] [-B num [-C[num]]
    [-e pattern] [-f file] [--binary-files=value] [--context[=num]]
    [--line-buffered] [pattern] [file ...]

    So it’s definitely there in Vista Ultimate.

    What version of Windows are you using?

  3. User Gravatar Alistair said:

    July 12th, 2009 at 12:41 am (#)

    You could try Grep for Windows:

    http://gnuwin32.sourceforge.net/packages/grep.htm

  4. User Gravatar dpsguard said:

    July 12th, 2009 at 7:39 pm (#)

    I am running Vista Ultimate. I did research on Microsoft and I can not find any reference of built-in Grep in Vista Ultimate. Not sure if I need to turn on Unix based applications subsystem.

  5. User Gravatar Alistair said:

    July 14th, 2009 at 7:50 am (#)

    I’m running SUA (Subsystem for UNIX-based Applications), but I wouldn’t have thought that would add utilities like grep to the Windows command shell – though they’re certainly all available in the SUA shells.

  6. User Gravatar nightstalker said:

    February 14th, 2010 at 9:07 pm (#)

    Correct me if I'm wrong but arent "grep" and "ps" unix/linux commands? The above method does't work for me.

  7. User Gravatar Franckjunior said:

    February 19th, 2010 at 6:48 pm (#)

    nao deu certo este procedimento no win2003 server.

  8. User Gravatar jeff said:

    March 12th, 2010 at 5:09 pm (#)

    dumbass.. this isn't for windows. it's for unix.

  9. User Gravatar itauthor said:

    March 16th, 2010 at 12:31 am (#)

    Yes, you're right. I had SFU (Services for UNIX) installed at the time, which gives you UNIX commands and makes some of them available at the Windows command prompt.

    >3 years later SFU has been replaced by SUA in Vista/Win7 Business/Ultimate, Server 2003 R2 and Server 2008. I've just checked and you no longer get the ps command in the Windows command console (although you *do* still get grep after enabling and installing SUA). So, for the above to work, you need to be within an SUA shell.

    However, you can achieve the same result using Windows PowerShell these days. For example, I just did the following:

    PS C:\\Users\\Alistair> netstat -ano|grep 1628
    TCP 192.168.0.191:1628 209.85.229.109:995 ESTABLISHED 2068
    PS C:\\Users\\Alistair> ps|grep 2068
    604 48 11232 7000 105 4.46 2068 GoogleDesktop

  10. User Gravatar itauthor said:

    March 16th, 2010 at 12:32 am (#)

    Hi Jeff. Thanks for your kind, considered and educated comment. So charmingly phrased as well!
    Take a lesson in manners from nightstalker's question above.

  11. User Gravatar mark said:

    October 29th, 2010 at 3:35 pm (#)

    I used simple/free port tester tool http://porttest.blogspot.com/

  12. User Gravatar itauthor said:

    November 9th, 2010 at 5:56 pm (#)

    Thanks for the link Mark, I'll try that.

  13. User Gravatar Anand Jhunjhunwala said:

    November 17th, 2010 at 5:11 am (#)

    if you don't have grep then try using
    netstat -ano|findstr 1628

  14. User Gravatar holladibolla said:

    April 20th, 2011 at 8:02 am (#)

    In Windows it could be done as follows:

    netstat -ano | findstr PORT
    tasklist | findstr PID

  15. User Gravatar kaloli said:

    June 23rd, 2011 at 10:10 am (#)

    Thanks holladibolla, this works perfectly for me in Windows server 2003

  16. User Gravatar Krig said:

    September 6th, 2011 at 1:18 pm (#)

    Jeff u are a big dumbasssss…u asshole how can write such thing abt itauthor…

  17. User Gravatar guestx said:

    November 26th, 2011 at 6:54 am (#)

    how does one type the bar character in the CMD line window

  18. User Gravatar GingeGuest said:

    January 4th, 2012 at 5:25 pm (#)

    it should be the ' ' right about the enter key. Just press shift ' ' to get ' | '

  19. User Gravatar Cole said:

    May 29th, 2012 at 12:07 pm (#)

    Hello guys … I tried installing XAMPP on my windows machine …MySql is working just fine but Apache keeps complaining that my Port 80 and Port 443 is busy… what do i do plz?

  20. User Gravatar alex said:

    July 7th, 2012 at 7:25 am (#)

    C:Usersalex>netstat -o -n -a | findstr 0.0:80
    TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4