Check if a port is being used on a Windows machine
August 8th, 2007 18 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.
- Start > Run
- Enter cmd
- In the command console enter:
netstat -ano|grep portNumber
This lists any processes where the port number is included somewhere on the line. - 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.
- Make a note of the number at the end of the line. This is the process ID (PID).
- 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
- Rails Chronicles – Part 2 – July 2011
- Adding your choice of text editor to Flare’s Open With menu – December 2010
- Fix “No topics found” issue in CHM output – November 2010
- Perl basics for beginners (on Windows) – August 2010
- Preventing BBC iPlayer running all the time – November 2008
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
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?
July 12th, 2009 at 12:41 am (#)
You could try Grep for Windows:
http://gnuwin32.sourceforge.net/packages/grep.htm
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.
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.
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.
February 19th, 2010 at 6:48 pm (#)
nao deu certo este procedimento no win2003 server.
March 12th, 2010 at 5:09 pm (#)
dumbass.. this isn't for windows. it's for unix.
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
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.
October 29th, 2010 at 3:35 pm (#)
I used simple/free port tester tool http://porttest.blogspot.com/
November 9th, 2010 at 5:56 pm (#)
Thanks for the link Mark, I'll try that.
November 17th, 2010 at 5:11 am (#)
if you don't have grep then try using
netstat -ano|findstr 1628
April 20th, 2011 at 8:02 am (#)
In Windows it could be done as follows:
netstat -ano | findstr PORT
tasklist | findstr PID
June 23rd, 2011 at 10:10 am (#)
Thanks holladibolla, this works perfectly for me in Windows server 2003
September 6th, 2011 at 1:18 pm (#)
Jeff u are a big dumbasssss...u asshole how can write such thing abt itauthor...
November 26th, 2011 at 6:54 am (#)
how does one type the bar character in the CMD line window
January 4th, 2012 at 5:25 pm (#)
it should be the ' ' right about the enter key. Just press shift ' ' to get ' | '