Mac-Osx
在 Mac OS X 上使用程序 ID 記錄網路流量?
我想記錄 Mac OS X 伺服器上的所有網路流量(就像 tcpdump 一樣),但包括負責的程序的 ID。使用 lsof 只會給我目前的連接,而不是過去的連接。
有沒有辦法做到這一點?
問候, 約臣
雖然
nettop
很適合查看目前連接的快照,但您也可以使用tcpdump
來收集數據和處理資訊。使用tcpdump
選項-k
顯示擷取的流量的元數據。-k Control the display of packet metadata via an optional metadata_arg argument. This is useful when displaying packet saved in the pcap-ng file format or with interfaces that support the PKTAP data link type. By default, when the metadata_arg optional argument is not specified, any available packet metadata information is printed out. The metadata_arg argument controls the display of specific packet metadata information using a flag word, where each character corresponds to a type of packet metadata as follows: I interface name (or interface ID) N process name P process ID S service class D direction C comment This is an Apple modification.
因此,例如顯示程序 ID 和程序名稱,您可以這樣做:
tcpdump -k NP