Show listening ports windows

netstat netstat

Область применения: Windows Server (половина ежегодного канала), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012 Applies to: Windows Server (Semi-Annual Channel), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012

Отображаются активные TCP-подключения, порты, на которых компьютер прослушивается, статистика Ethernet, таблица маршрутизации IP-адресов, статистика IPv4 (для протоколов IP, ICMP, TCP и UDP) и Статистика IPv6 (для протоколов IPv6, ICMPv6, TCP по IPv6 и UDP через IPv6). Displays active TCP connections, ports on which the computer is listening, Ethernet statistics, the IP routing table, IPv4 statistics (for the IP, ICMP, TCP, and UDP protocols), and IPv6 statistics (for the IPv6, ICMPv6, TCP over IPv6, and UDP over IPv6 protocols). При использовании без параметров эта команда отображает активные TCP-подключения. Used without parameters, this command displays active TCP connections.

Эта команда доступна, только если протокол Internet Protocol (TCP/IP) установлен в качестве компонента в свойствах сетевого адаптера в окне Сетевые подключения. This command is available only if the Internet Protocol (TCP/IP) protocol is installed as a component in the properties of a network adapter in Network Connections.

Синтаксис Syntax

Параметры Parameters

Параметр Parameter Описание Description
-a -a Отображает все активные TCP-подключения и порты TCP и UDP, прослушиваемые компьютером. Displays all active TCP connections and the TCP and UDP ports on which the computer is listening.
-b -b Отображает исполняемый файл, участвующий в создании каждого подключения или порта прослушивания. Displays the executable involved in creating each connection or listening port. В некоторых случаях хорошо известные исполняемые объекты размещают несколько независимых компонентов, и в этих случаях отображается последовательность компонентов, участвующих в создании подключения или порта прослушивания. In some cases well-known executables host multiple independent components, and in these cases the sequence of components involved in creating the connection or listening port is displayed. В этом случае имя исполняемого файла находится в [] в нижней части, в верхней — это компонент, который он вызвал, и так далее, пока не достигнет TCP/IP. In this case the executable name is in [] at the bottom, on top is the component it called, and so forth until TCP/IP was reached. Обратите внимание, что этот параметр может занимать много времени и не будет работать, если у вас нет достаточных разрешений. Note that this option can be time-consuming and will fail unless you have sufficient permissions.
-E -e Отображает статистику Ethernet, например число отправленных и полученных байтов и пакетов. Displays Ethernet statistics, such as the number of bytes and packets sent and received. Этот параметр можно сочетать с -s. This parameter can be combined with -s.
-n -n Отображает активные TCP-подключения, однако адреса и номера портов выражаются в числовом виде, и для определения имен не выполняется никаких попыток. Displays active TCP connections, however, addresses and port numbers are expressed numerically and no attempt is made to determine names.
-o -o Отображает активные TCP-подключения и включает идентификатор процесса (PID) для каждого подключения. Displays active TCP connections and includes the process ID (PID) for each connection. Приложение, основанное на PID, можно найти на вкладке процессы в диспетчере задач Windows. You can find the application based on the PID on the Processes tab in Windows Task Manager. Этот параметр можно сочетать с параметрами -a, -n и -p. This parameter can be combined with -a, -n, and -p.
-p

Показывает соединения для протокола, заданного протоколом. Shows connections for the protocol specified by Protocol. В этом случае протоколом может быть TCP, UDP, TCPv6 или UDPv6. In this case, the Protocol can be tcp, udp, tcpv6, or udpv6. Если этот параметр используется вместе с -s для вывода статистики по протоколу, протокол может принимать значение TCP, UDP, ICMP, IP, tcpv6, udpv6, ICMPv6 или IPv6. If this parameter is used with -s to display statistics by protocol, Protocol can be tcp, udp, icmp, ip, tcpv6, udpv6, icmpv6, or ipv6. -S -s Отображает статистику по протоколу. Displays statistics by protocol. По умолчанию для протоколов TCP, UDP, ICMP и IP отображается статистика. By default, statistics are shown for the TCP, UDP, ICMP, and IP protocols. Если установлен протокол IPv6, для протоколов TCP через IPv6, UDP через IPv6, ICMPv6 и IPv6 отображаются статистические данные. If the IPv6 protocol is installed, statistics are shown for the TCP over IPv6, UDP over IPv6, ICMPv6, and IPv6 protocols. Параметр -p можно использовать для указания набора протоколов. The -p parameter can be used to specify a set of protocols. -r -r Отображает содержимое таблицы IP-маршрутизации. Displays the contents of the IP routing table. Это эквивалентно команде Route Print. This is equivalent to the route print command. Повторно отображает выбранную информацию каждый интервал в секундах. Redisplays the selected information every interval seconds. Нажмите клавиши CTRL + C, чтобы прерывать повторное отображение. Press CTRL+C to stop the redisplay. Если этот параметр не указан, эта команда выводит выбранные данные только один раз. If this parameter is omitted, this command prints the selected information only once. /? /? Отображение справки в командной строке. Displays help at the command prompt.

Комментарии Remarks

Команда netstat предоставляет статистические данные по следующим параметрам: The netstat command provides statistics for the following:

Параметр Parameter Описание Description
Proto Proto Имя протокола (TCP или UDP). The name of the protocol (TCP or UDP).
Локальный адрес Local address IP-адрес локального компьютера и используемый номер порта. The IP address of the local computer and the port number being used. Имя локального компьютера, соответствующее IP-адресу и имя порта, отображается, если не указан параметр -n . The name of the local computer that corresponds to the IP address and the name of the port is shown unless the -n parameter is specified. Если порт еще не установлен, номер порта отображается в виде звездочки (*). If the port is not yet established, the port number is shown as an asterisk (*).
Внешний адрес Foreign address IP-адрес и номер порта удаленного компьютера, к которому подключен сокет. The IP address and port number of the remote computer to which the socket is connected. Имена, соответствующие IP-адресу и порту, отображаются, если не указан параметр -n . The names that corresponds to the IP address and the port are shown unless the -n parameter is specified. Если порт еще не установлен, номер порта отображается в виде звездочки (*). If the port is not yet established, the port number is shown as an asterisk (*).
Состояние State Указывает состояние TCP-подключения, включая: Indicates the state of a TCP connection, including:
  • CLOSE_WAIT CLOSE_WAIT
  • CLOSED CLOSED
  • УСТАНОВИТЬ ESTABLISHED
  • FIN_WAIT_1 FIN_WAIT_1
  • FIN_WAIT_2 FIN_WAIT_2
  • LAST_ACK LAST_ACK
  • СЛУШИВАЮТ LISTEN
  • SYN_RECEIVED SYN_RECEIVED
  • SYN_SEND SYN_SEND
  • TIMED_WAIT TIMED_WAIT

Примеры Examples

Чтобы отобразить статистику Ethernet и статистику для всех протоколов, введите: To display both the Ethernet statistics and the statistics for all protocols, type:

Чтобы отобразить статистику только для протоколов TCP и UDP, введите: To display the statistics for only the TCP and UDP protocols, type:

Чтобы отобразить активные TCP-подключения и идентификаторы процессов каждые 5 секунд, введите: To display active TCP connections and the process IDs every 5 seconds, type:

Чтобы отобразить активные TCP-подключения и идентификаторы процессов в числовом формате, введите: To display active TCP connections and the process IDs using numerical form, type:

Use Netstat to See Listening Ports and PID in Windows

You never know when this will come in handy

In another article, we explained computer ports and what they’re used for. Other than that, what can we do with port information? Since all traffic in and out of the computer goes through ports, we can check on them to see what they’re doing. Maybe the port isn’t listening for traffic? Maybe something is using a port that shouldn’t be?

We’re going to use the Windows command netstat to see our listening ports and PID (Process ID). We’re also going to see what we can do with that information.

What Is Netstat?

The netstat command is a combination of the words ‘network’ and ‘statistics’. The netstat command works in all versions of Windows from Windows XP right up to Windows 10. It’s also used in other operating systems (OS) like Unix and Linux, but we’ll stick to Windows here.

Netstat can provide us with:

  • The name of the protocol the port is using (TCP or UDP).
  • The local IP address and name of the computer and the port number being used.
  • The IP address and port number to which we’re connecting.
  • The state of a TCP connection. For details on what these states are, read the Event Processing section of RFC 793.

Using Netstat To See Listening Ports & PID

  • Use the key combination Win Key + X. In the menu that opens, select Command Prompt.

  • Enter the command . The parameters for netstat are preceded with a hyphen, not a forward slash like many other commands. The -a tells it to show us all active connections and the ports on which the computer is listening.

The -n tells netstat to show the IP addresses and ports as numbers only. We’re telling it to not try to resolve the names. This makes for a quicker and neater display. The -o tells netstat to include the PID. We’ll use the PID later to find out what process is using a specific port.

  • View the results and take note of the addresses, port numbers, state, and PID. Let’s say we want to know what’s using port 63240. Note that its PID is 8552 and it’s connecting to the IP address 172.217.12.138 on port 443.

What’s Using That Port?

  • Open Task Manager. That’s most easily done by using the key combination Ctrl + Shift + Esc.

  • Click on the Details tab. To make this easier to find, click on the PID column header to sort the PIDs numerically.

  • Scroll down to PID 8552 and see what process it is. In this case, it’s googledrivesync.exe. But is it really? Sometimes viruses can make themselves look like legitimate processes.

  • In a web browser, go to ipinfo.io. Enter the IP address 172.217.12.138. As we can see, the IP address is registered to Google. So this googledrivesync.exe is a legitimate one.

How To Get Port, PID, & Process Name In PowerShell

PowerShell is Microsoft’s newer way to use a command-line interface with Windows. We say newer, but it’s been around for several versions. You should learn PowerShell even if you’re a home user.

Most Windows commands also work in PowerShell, plus we can combine them with PowerShell’s cmdlets – pronounced command-lets. Joe at Winteltools.com provides the script for this method.

  • Open Notepad and enter the following code:

  • Save the file as get-NetstatProcessName.ps1. Make sure to note where it’s being saved. It’s important to change the Save as type: to All Files (*.*) or it will get saved as get-NetstatProcessName.ps1.txt and it won’t work for us.

  • Open PowerShell and navigate to the location in which the script was saved. In this case, it’s . Hit Enter to run the command.

  • Run the script using dot-sourcing to make it work. That means use ./ before the name of the file. The command will be

  • Now we can see all the traditional netstat info plus the process name. No need to open Task Manager anymore.

Go Get Them

We’ve covered two ways to use the netstat command to see listening ports. It can be used either in the old Command Prompt or within a PowerShell script. With the information it can give us, we’ve looked at how it can help us figure out what our computer is doing.

If you thought netstat is a great utility, take a look at some other Windows TCP/IP utilities like tracert, ipconfig, and nslookup. Or use Resource Monitor to get a better look into hidden website and Internet connections. There is a lot you can do to see exactly what your computer is doing.

Have you used netstat to solve a problem? Please tell us what you did. Any questions about how to use netstat? Please ask us in the comments below.

Guy has been published online and in print newspapers, nominated for writing awards, and cited in scholarly papers due to his ability to speak tech to anyone, but still prefers analog watches. Read Guy’s Full Bio

Читайте также:  New windows keep opening
Оцените статью