回答:
-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. 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.
注:管理者netstat -b特権のコマンドプロンプトから実行しない限り、コマンドは失敗します。
プロセスリストをフィルタリングし、興味のあるPIDを見つけます。
tasklist | findstr /c:"PID"
Tcpvcon.exe代わりに使用できます。管理者権限は不要です。
Tcpvconの使用法は、組み込みのWindows
netstatユーティリティの使用法に似ています。
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.
SysInternalsのTCPViewを探していると思います。
次に、出力FORを解析してからpidのフィルターを使用してプロセス名を表示するためのウィンドウの例を示します。 netstatDO tasklist/fi
最後の発見は、tasklistヘッダーを削除することです。
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
netstatトークンを追加することで、追加のフィールドを追加できます。
findポートを除外するために使用(対照的に、netstat -bプロセス名を直接提供できますが、出力を手動で検索するのは苦痛でエラーが発生しやすい)。2. Windowsネイティブコマンドのみを使用します。これは、より柔軟で独立しています。
findstr、/Rオプションで使用するfind。2. ローカルポートのみ:443 *[[0-9]"を除外するパターンとして使用します。コマンド全体は次のようになりますFOR /F "usebackq tokens=5 delims= " %i IN (`netstat -ano ^|findstr /R /C:":443 *[[0-9]"`) DO @tasklist /fi "pid eq %i" | findstr "%i"
netstatトークンを追加することで追加フィールドを追加できます」を明確にできますか?
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-システムサービスでは動作しません。また、ProcessNamePID値を置き換えるのではなく、行の末尾に追加することもできます。
楽しめ ;)
これを使用してみてください...
タイムライン付きのプロセス名:) onelinerで...スクリプトをすばやく簡単に作成する必要はありません...
ESTABLISHEDまたはLISTENINGによってパラメーターSYN_SENTを変更できます
filter timestamp {"$(Get-Date -Format G): $_"};netstat -abno 1 | Select-String -Context 0,1 -Pattern LISTENING|timestamp
filter timestamp {"$(Get-Date -Format G): $_"};netstat -abno 1 | Select-String -Context 0,1 -Pattern SYN_SENT|timestamp
とてもいいエリック・ビテモ!パスに変数を追加することを考えていたのですが、定義されていませんが、あなたはすでにそれを持っていることに気付きました。したがって、再利用したコードは次のとおりです。
$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*"}
}
多少異なる2ライナーを使用したアプリケーションのプロセスとサービスを見つけようとしていました。
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
GetServiceとGet-Process。