- Command line for looking at specific port
- 14 Answers 14
- How to check which TCP/IP ports are in use in Windows 8?
- TCP/IP ports
- Use the command line and Task Manager to check the ports
- About Nick
- How to check if a port is blocked on a Windows machine?
- 4 Answers 4
- How to find out which ports are used by a program?
- 3 Answers 3
- Checking the port number in windows using bat file
- 3 Answers 3
Command line for looking at specific port
Is there a way to examine the status of a specific port from the Windows command line? I know I can use netstat to examine all ports but netstat is slow and looking at a specific port probably isn’t.
14 Answers 14
Here is the easy solution of port finding.
You can use the netstat combined with the -np flags and a pipe to the find or findstr commands.
Basic Usage is as such:
So for example to check port 80 on TCP, you can do this: netstat -np TCP | find «80» Which ends up giving the following kind of output:
As you can see, this only shows the connections on port 80 for the TCP protocol.
here o represents process ID. now you can do whatever with the process ID. To terminate the process, for e.g., use:
when I have problem with WAMP apache , I use this code for find which program is using port 80.
3068 is PID, so I can find it from task manager and stop that process.
As noted elsewhere: use netstat, with appropriate switches, and then filter the results with find[str]
To find a foreign port you could use:
To find a local port you might use:
Where N is the port number you are interested in.
-n ensures all ports will be numerical, i.e. not returned as translated to service names.
-a will ensure you search all connections (TCP, UDP, listening. )
In the find string you must include the colon, as the port qualifier, otherwise the number may match either local or foreign addresses.
You can further narrow narrow the search using other netstat switches as necessary.
Further reading (^0^)
it will give you number of sockets active on a specific IP and port(Server port number)
For Windows 8 User : Open Command Prompt, type netstat -an | find «your port number» , enter .
If reply comes like LISTENING then the port is in use, else it is free .
To find a foreign port (IPv4 or IPv6) you can use:
To find a local port (IPv4 or IPv6) you can use:
Where N is the port number you are interested in. The «/r» switch tells it to process it as regexp. The «/c» switch allows findstr to include spaces within search strings instead of treating a space as a search string delimiter. This added space prevents longer ports being mistreated — for example, «:80» vs «:8080» and other port munging issues.
To list remote connections to the local RDP server, for example:
Or to see who is touching your DNS:
If you want to exclude local-only ports you can use a series of exceptions with «/v» and escape characters with a backslash:
How to check which TCP/IP ports are in use in Windows 8?
Every programs need to occupy an available port or socket for being connected to a network. The network may be an Intranet or it can be the internet. Suppose you are connecting two or more computers through LAN, or you are making a cluster of computers for some high performance work, you need to communicate between the programs running in those computers. For that you need to know the IP address and the port/socket number to find any specific application. If you only tell the name of the application, then that won’t work. Because behind the scene, each application is uniquely identified by its unique id and these Ids are associated with the ports or sockets.
TCP/IP ports
Each application used its current socket for its entire lifetime. i.e., it can get a new port address when you run it for the next time. but it can’t change once it got a port number till the termination.
Some applications have dedicated fixed ports, like HTTP (Hyper Text Transfer protocol) uses port 80, FTP (File Transfer Protocol) uses port 21 or 20, Telnet has dedicated port 23,
SMTP (Simple Mail Transfer Protocol) uses port 25 etc. Port number 1 to 1024 are reserved for these system tasks purpose. The other port addresses are used for other applications.
To check which application is using what port, you can follow the procedure shown below.
Use the command line and Task Manager to check the ports
1. Open the Task Manager, by right clicking on the taskbar and then selecting Open Task Manager
or by pressing the buttons Ctrl + Shift + Esc. Now go to the File Tab -> Run new task.
2. Then you will see Run window. Check the box at the bottom showing Create this task with administrative privileges to run the task as an administrator.
Write cmd into the input area and press Enter. Or you can simply use the Quick Access Menu by pressing Windows + X.
Now, the administrative command prompt will appear. You will see Administrator is written in the bar. It indicates that you have the privilege to perform administrative tasks.
3. Now, simply type this command
netstat -aon | more
in the command prompt
and press Enter.
4. Now you will see a table with the Local Address column, which will show you the port address and PID column, which shows the Process Identifier (PID) number of the process which is listening (using) to that particular port. In the figure given below, from the table, you can see that Local Address 0.0.0.0:554 or port 554 is being used (Listening) by the process having the PID 6492.
The PID is the unique identifier for each and every process and no other process can get this ID when this process is running. This PID can be given to another process after the termination of this one.
5. Now, open theTask Manager and navigate to the Services tab, there you will get the PIDs of all programs running correctly. Here I find that can see that WMPNetworkSvc has the PID 6492 and currently, it is running. So it is clear that WMPNetworkSvc is using port 554 now. You can terminate this program to release the port from this application.
Thus you can easily checkout, which port is listening to which program and what are the available ports.
About Nick
Nick is a Software Engineer. He has interest in gadgets and technical stuffs. If you are facing any problem with your Windows, feel free to ask him.
How to check if a port is blocked on a Windows machine?
On the Windows platform, what native options to I have to check if a port (3306, for example) on my local machine (as in localhost ), is being blocked?
4 Answers 4
Since you are on a Windows machine, these things can be done:
Execute the following command and look for a «:3306» listener (you did not mention UDP/TCP). This will confirm there is something running on the port.
After this, if you are expecting incoming connections on this port and feel that the firewall may be blocking them, you could use start windows firewall logging and check the logs for dropped connections
- Go to Windows Firewall, Advanced settings
- Click on the Settings button next to «Local Area Connection»
- Select «Log dropped packets»
- Look at the log file location (if not present, define one)
- Click OK
- Now, when the connection attempt is made (assuming you know when this is done), look at the log file for a drop on port 3306.
- If this is seen, you will want to add an exception for this port.
There is one more command to check the firewall state
(Updated for Windows 7 users — as referred by Nick below — use netsh advfirewall firewall)
netsh firewall show state
- this will list the blocked ports as well as active listening ports with application associations
This command will dump the Windows firewall configuration detail
netsh firewall show config
If you have an active block (incoming connections are being dropped by firewall) after you start logging, you should see that in the log.
If you are running an application/service that is listening on 3306, the firewall config should show it to be Enabled. If this is not seen, you have probably missed adding an exception with the firewall to allow this app/service.
Finally, port 3306 is typically used for MySQL. So, I presume you are running MySQL server on this windows machine. You should therefore see a listener for 3306 accepting incoming connections. If you do not see that, you need to work with your application (MySQL) to get that started first.
How to find out which ports are used by a program?
I try to figure out which ports a specific program uses if they send data to the internet. Is there a tool which is able to find this out? Or do I have to do package inspection by using wireshark?
Background: I try to create a priority rule on my fritz!box 7490 router, so that some computer games are seen as real-time applications and there are as less lags as possible e.g. if someone in the network decides to watch videos on youtube while I am playing online.
3 Answers 3
Determine PID of your program
Check ports in third column of output from
- there is a space before PID to rule out inappropriate matches potentially coming from other columns (a little trick)
- /n keeps addresses in numeric form (without resolving) what causes the command to finish without delays (it should suffice for what you need)
If you are using windows you can use the free utility «Process Explorer» for this — among many other things. You have to run it in Administrator mode though.
If you are wanting to optimize something like a game or netflix streaming, then you don’t need to worry about the port on your computer — that is the client, and is (somewhat) randomly chosen from the higher range of ports. What you want is to find out what port(s) the service you are connecting to is provided on, and optimize connections to those ports from your machine (possibly by MAC address? or local lan ip)
Checking the port number in windows using bat file
I would like to check the two ports are running or not.In case if any of the port is running means have to check the next port number and write the unused port number in the file.
For ex:tomcat default port number is 8080 and oracle port number 1521. Assume the inputs are 8080 and 1521. In-case if the 8080 is running have to check 8081 and in-case if this port also running means have to check the unused port number.Assume got the unused port number is 8086. And this port has to write in the file Tomcat_port=8086.
The same for checking oracle port number also.
I am new to scripting please help me to solve this.
3 Answers 3
There is in batch scritping, a command that allow you to determine if a port is already used or not.
After that, an error «ERRORLEVEL» is raised, to tell you if your criteria was reached or not. ERRORLEVEL equals 0 if everything works fine and is greater than 0 if not.
Assuming that, find below a script that ask you a starting port, and automatically stop if there is an available port for you. It also write that port in a file named Availables.txt
Tell me if it worked for you or for any question.
This code defines a subroutine/function ( findFirstAvailablePort ) to do the work or searching for the first available TCP port from the starting indicated number. The value is returned in a variable (also passed on subroutine call).
This function is then called twice to retrieve the availables port starting from 8080 and 1521. Then the retrieved data is echoed to console.
The work in the function is divided in two parts.
The first part reads the output of the netstat command and splits the line to retrieve the list of open ports and generate a temporary file to analyze.
The second iterates checking the port numbers against the temporary file searching for the first port number that can not be found.