Command line for looking at specific port
Command line for looking at specific port
Question
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.
Popular Answer
Here is the easy solution of port finding...
In cmd:
netstat -na | find "8080"
In bash:
netstat -na | grep "8080"
In PowerShell:
netstat -na | Select-String "8080"
Read more… Read less…
You can use the netstat
combined with the -np
flags and a pipe to the find
or findstr
commands.
Basic Usage is as such:
netstat -np <protocol> | find "port #"
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:
TCP 192.168.0.105:50466 64.34.119.101:80 ESTABLISHED
TCP 192.168.0.105:50496 64.34.119.101:80 ESTABLISHED
As you can see, this only shows the connections on port 80 for the TCP protocol.
I use:
netstat –aon | find "<port number>"
here o represents process ID. now you can do whatever with the process ID. To terminate the process, for e.g., use:
taskkill /F /pid <process ID>
when I have problem with WAMP apache , I use this code for find which program is using port 80.
netstat -o -n -a | findstr 0.0: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]
Most basic:
netstat -an | find ":N"
or
netstat -a -n | find ":N"
To find a foreign port you could use:
netstat -an | findstr ":N[^:]*$"
To find a local port you might use:
netstat -an | findstr ":N.*:[^:]*$"
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^)
netstat /?
find /?
findstr /?
netstat -a -n | find /c "10.240.199.9:8080"
it will give you number of sockets active on a specific IP and port(Server port number)