Now Available:

Featured Resource:

line

Newsletter

Email Address:


line

Ask the Expert

Have a question for our resident expert? Email your questions to Greg.

« Citrix Announces XenApp 5.0 - To Be Released September 10th | Main | Have you Signed Up for our Monthly e-Journals Yet? »

Determining the Ports Used by a Service

The Ask the Performance Team has a great post from earlier this week that discusses the use of the NETSTAT.EXE command line tool in determining the network ports used by a service.  Using the right combination of switches, netstat -a -n -o will display the list of ports on which the server is currently listening.  The TASKLIST.EXE process can then be used to cross-reference process IDs (PIDs) with process names.

From the post, which can be found in its entirety here:

So how do we determine the port that a service is using?  Without using Network Monitor, Wireshark or a similar utility, there are a couple of very handy utilities provided with the operating system that we can use – NETSTAT.EXE and TASKLIST.EXE.  Most administrators are familiar with NETSTAT.EXE already, but for those who are not, you can use NETSTAT.EXE to identify what ports are being used by a particular process.  The syntax that we will be using for NETSTAT.EXE is as follows: netstat.exe –a –n –o.  The switches we are using provide the following:

  • -a: listing of all connections and listening ports
  • -n: display address and port numbers in numerical form
  • -o: display the owning PID associated with each connection

When the command is run, you will see output similar to what is below.  Something to keep in mind is that in the Proto column, the protocol may be TCP or UDP.

If there is a specific port in use that we want to examine, we need the PID of the owning process, and TASKLIST.EXE.

The article continues to discuss the steps used in unwrapping the individual services that are encapsulated by a svchost.exe process.  All-in-all, a very handy exercise.

TrackBack

TrackBack URL for this entry:
http://www.realtime-windowsserver.com/type/mt-tb.cgi/926

Comments

It's weird that Microsoft themselves would advise using the -o parameter to obtain the PID, then take a second step to look up the executable that matches the PID.

... because the -b parameter tells you directly both the PID and the executable name!

netstat -b

I think that both the -b and -o parameters were added in XP and 2003 and up.

Post a comment

(All comments are approved by site leader before appearing here. Thanks for commenting!)

line

Greg Shields' Bio:

Greg Shields, is an independent author, instructor, and IT consultant based in Denver, Colorado, and a co-founder of Concentrated Technology. With nearly 15 years of experience in information technology, Greg has developed extensive experience in systems administration, engineering, and architecture specializing in Microsoft systems management, remote application, and virtualization technologies. Greg is a Contributing Editor for Redmond Magazine, MCPmag.com, and Virtualization Review Magazine and is the author of five books, including Windows Server 2008:  What’s New / What’s Changed. Greg is also a highly sought-after instructor and speaker, speaking regularly at conferences like TechMentor Events, and producing computer-based training curriculum for CBT Nuggets.  Greg is a recipient of Microsoft "Most Valuable Professional" award with a specialization in Windows Terminal Services.