Thursday 15 May 2014

netstat commands for port manipulation

Topics covered, how to:
  • See if port 8080 is in use
  • See which application is using localhost:8080
  • Find out the Process ID that is using port 8080
  • Locate the PID and its application in Task Manager
Steps:
The following steps were performed on a Windows 7 machine.
See if port 8080 is in use
1)  Open the Windows Start menu, type cmd in the search box, and press Enter on your keyboard to open a Command Prompt window.
2)  At the prompt, type netstat –a. This will show the ports on your machine, as shown below.
3.png

A closer look at port 8080 shows us it is in 'Listening' state, but it doesn't tell us which application is using it.
4.png

See which application is using localhost:8080
3)  The quickest way to find out which application is listening to port 8080, is to open a web browser and type the following in the address bar:  localhost:8080
If you’re lucky, you will see a result, for example the IIS default page.
5.png
This lets us know immediately that the problem is IIS. Port 80 is the default for IIS, but perhaps somewhere along the way it got changed to port 8080.
4)  In that case, stop the IIS server. To prevent IIS from listening to port 8080 and conflict with Apache Tomcat, follow the steps in this link to change the TCP port for IIS services.
  • Here is a list of well-known ports you can choose from.
Note: You can have Apache and IIS running simultaneously on the same web server, assuming you have two IP addresses on the box.
5)  Now that the 8080 port is open, run the Akula installer to complete the Tomcat and remainder of the Akula installation.

Find out the Process ID that is using port 8080
Sometimes you won’t be so lucky and typing localhost:8080 in the browser address bar returns an empty page. We confirmed earlier by running the netstat –a command that something is indeed listening on port 8080. So, the next step is to find out which process is taking up port 8080 - and that will eventually lead us to the application that is using it.
6)  Open the Windows Start menu, type cmd in the search box, and press Enter.
7)  At the prompt, type the following command:
netstat -o -n -a | findstr "8080”
6.png

8)  Press Enter.
The result will show you the PID (process ID) that the 8080 port is listening to, as shown below.
7.png

Note: The netstat -o option is used to display active TCP connections and includes the process ID (PID) for each connection. This parameter can be combined with -a-n, and -p. More information on netstat command-line parameters can be found here.

Locate the PID and its application in Task Manager
The result of the netstat command tells us that the process with PID 8280 is listening on port 8080. The next step is to locate that PID in Windows Task Manager.
9)  Open the Task Manager and select the Processes tab.
8.png

10)  If the PID column is not visible, select the View menu > Select Columns…
9.png

11)  Select the PID (Process Identifier) checkbox to add that column to the Processes view.
10.png

12)  To make it easier to view the Process IDs, click the PID column to sort it.
11.png

13)  If the Process ID that is using port 8080 is not listed, select the Show processes from all users checkbox at the bottom of the Task Manager.
12.png

Once the correct PID is identified, look at its corresponding Image Name in the left column (the 'Image Name' is the name of the executable file used when the process was created). This should tell us the name of the application running the process.
15) Stop that application.
16) Once the application listening to port 8080 is stopped, run the Akula installer to complete the Tomcat and remainder of the Akula installation.

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...