2014-01-26 16:07:42 +0000 2014-01-26 16:07:42 +0000
46
46
Advertisement

プロセス名でnetstat?

Advertisement

netstat -a -o -n を使ってポートのリストと PID

を取得した後、タスクマネージャに行って PID を追加して誰がそれをやっているのかを確認する必要があります。(かなりイライラします)

全てを行うCMDコマンドがあるかどうか疑問に思いました( find , for , powershellを使用)

そうすればプロセス名を取得できます。

Advertisement
Advertisement

回答 (6)

56
56
56
2014-01-26 18:06:00 +0000
-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. 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.

注意 -bコマンドは、昇格したコマンドプロンプトから実行しないと失敗します。

tasklist | findstr /c:"PID"

回避策

プロセスリストをフィルタリングして、興味のある PID を見つけてください。

Usage: tcpvcon [-a] [-c] [-n] [process name or PID]

 -a Show all endpoints (default is to show established TCP connections).
 -c Print output as CSV.
 -n Don't resolve addresses.

代替方法

代わりに netstat -b を使用することができます。管理者権限は必要ありません。

Tcpvcon の使用方法は Windows 組み込みの Tcpvcon.exe ユーティリティに似ています。

0x1&

8
8
8
2014-01-26 16:12:23 +0000

SysInternalsの TCPView を探していると思います。

2
Advertisement
2
2
2016-05-13 02:17:35 +0000
Advertisement

Windows の例は、FOR を使って netstat の出力を解析し、DO tasklist の出力を /fi tasklist にして、pid に netstat フィルタをかけてプロセス名を表示しています。

最後の発見は、0x6& ヘッダを削除することです。

FOR /F "usebackq tokens=5 delims= " %i IN (`netstat -ano ^|find "443"`) DO @tasklist /fi "pid eq %i" | find "%i"

は、

tomcat8.exe.x64 4240 Services 0 931,864 K

のようにレコードを出力します。

2
2
2
2016-03-07 22:14:01 +0000

PS を使うのが好きなら、このコードをフォークすることができます (注意: 超基本的なコードです)

$nets = netstat -ano | select-string LISTENING
foreach($n in $nets){
    # make split easier PLUS make it a string instead of a match object:
    $p = $n -replace ' +',' '
    # make it an array:
    $nar = $p.Split(' ')
    # pick last item:
    $pname = $(Get-Process -id $nar[-1]).ProcessName
    $ppath = $(Get-Process -id $nar[-1]).Path
    # print the modified line with processname instead of PID:
    $n -replace "$($nar[-1])","$($ppath) $($pname)"
}

完全な実行パスを得るために、Path の代わりに ProcessName を試すことができることに注意してください - ただし、システムサービスでは動作しません。また、PID値を置き換える代わりに、行の最後にProcessNameを追加した方が良いかもしれません。

お楽しみください ;)

1
Advertisement
1
1
2018-02-11 10:10:26 +0000
Advertisement

これを使ってみて

タイムスタンプ付きのプロセス名 :) を oneliner で指定してみた。

0
0
0
2017-10-07 12:37:30 +0000

非常に素晴らしいErik Bitemo! 私はパスの変数を追加しようと考えていましたが、それが定義されていないにもかかわらず、あなたはすでにそれを持っていることに気づきました。

$nets = netstat -ano |select-string LISTENING;
foreach ($n in $nets)
    {
# make split easier PLUS make it a string instead of a match object
    $p = $n -replace ' +',' ';
# make it an array
    $nar = $p.Split(' ')
# pick last item...
    $pname = $(Get-Process -id $nar[-1]).ProcessName
    $ppath = $(Get-Process -id $nar[-1]).Path;
# print the modified line with processname instead of PID
    $n -replace "$($nar[-1])","$($ppath) $($pname)" | where {$pname -like "*GMSVP*"}
     }

私はアプリケーションのプロセスとサービスを見つけようとしていたので、私が再利用したコードは次のとおりです。

Get-Service | select status,name,displayname,servicename | where {($_.DisplayName -like "myserv*") -or ($_.servicename -like "post*")} | ft -auto

Get-Process | select id, processname,cpu,path,description | where {$_.path -like "*myserv*"} | ft -auto
Advertisement

関連する質問

3
28
13
7
2
Advertisement
Advertisement