lsofコマンドを使用してlocalhostを無視し、TCP設定接続を一覧表示する方法は?

lsofコマンドを使用してlocalhostを無視し、TCP設定接続を一覧表示する方法は?

コマンドを使用してステータスへの接続をlsof印刷したいが、localhostへの接続は無視されます。TCPESTABLISHED

私は試した:

lsof -itcp@^127.0.0.1 -stcp:established
lsof -itcp@(^127.0.0.1) -stcp:established
lsof -itcp -i ^@127.0.0.1 -stcp:established

他のものと似ていますが、常に構文エラー応答を受け取ります。

正しい構文は何ですか?

ベストアンサー1

でネットワークアドレスを否定できないようですlsof

lsfdLinuxでは、次のものを代わりに使用できますutil-linux

lsfd -Q '(type =~ "^TCP") and
         (name =~ "state=established") and
         (name !~ "addr=(\[::1\]|127)")'

または@ABがss述べたようにiproute2

ss -tp state established not dst 127.0/8 not dst '[::1]'

おすすめ記事