I would like to examine the network traffic being handled by a single process, but simple network captures won't work since I am dealing with such a busy system (lots of other traffic happening at the same time). Is there a way to isolate a tcpdump or wireshark capture to the networking traffic of a single specific process? (Using netstat is insufficient.)
|
|
||||
|
|
|
Indeed there is a way, using the wireshark filters. But you cannot filter directly by process name or PID (because are not network quantity). You should first figure out the protocols and the ports used by your process (the netstat command in the previous comment works well). Then use wireshark to filter the inbound (or outbound) port with the one you just retrieve. That should isolate the incoming and outcoming traffic of your process. |
|||||||||||||
|
|
To start and monitor an new process:
To monitor an existing process with a known pid:
|
|||
|
That will show the connections an application is making including the port being used. |
|||||
|
|
try running the process your interested in under strace.
will give you some very detailed information about what your process is doing. As a process can open up any ports it wants to anywhere, using a predefined filter you may miss something. Another approach would to use a stripped down virtual machine or a test machine on your network, and place your process on in isolation on this. Then you can just use wireshark to catch all from that machine, you'll be pretty sure that the traffic you capture will be relevant. |
|||
|
|
|
This is a dirty hack but I'd suggest either a divert or a log target with iptables for a given UID. eg:
It might also be worth looking into something like '--log-tcp-sequence', '--log-tcp-options', '--log-ip-options', '--log-uid' for that log target. Though I suspect that will only help you post process a pcap that includes a ton of other data. The NFLOG target might be useful if you want to flag packets and then certain tagged packets will be sent over a netlink socket to a process of your choosing. I wonder if that would be useful for hacking up something with wireshark and your specific application running as a specific user? |
|||
|
|
|
Just an idea: Is it possible to bind your application to a different IP? So that you can use the usual suspects (tcpdump...) Tools for applications which are not capable of binding to another ip: http://freshmeat.net/projects/fixsrcip
http://freshmeat.net/projects/force_bind
|
||||
|
Building on the answer by ioerror I suspect you can use Or indeed you could use this to send those packets out a different interface, and then capture only on that interface. |
|||
|
|
|
maybe iptables and ulog can work? Not that I have an exact recipe, but I think iptables can match processes, once matched you could use ulog. |
|||||
|
|
I think you can create a shell script to loop through executing netstat and logging it to a text file. something like (very rough steps) echo "press q to quit"
while [ ]
do
i am not a programmer so cant refine this. but someone here can start from where i left and create a working script for you. |
|||
|
|