You can alot run "lsof -i -T -n" from popen2 to see what applications use what port and addr they are connected to.<br>In order to see all jobs though it needs to be ran as root. This way you can find out what ports and such Then perform tcp dump thru popen2 and filter for port and addr. This is just a first shot, then I would figure out what to do after having gotten to this point.<br>
<br>import popen2<br>#find out what ports and addrs what program is connected to<br>r,w,e=popen2.popen3("lsof -i -T -n") # this may need sudo prepended to lsof<br>r=r.readlines()<br>e=e.readlines()<br>#get tcpdump, doesn't quiet work here....needs something more, maybe a different way altogether.<br>
#tcpdump to pcap file and read file periodically?<br>r1,w1,e1=popen2.popen3("sudo tcpdump -i eth1")<br>r1=r1.readlines()<br>e1=e1.readlines()<br><br>Something to this nature, then do regular expression on tcpdump output, either logged to pcap output file or by other means.<br>
<br clear="all">-Alex Goretoy<br><a href="http://www.alexgoretoy.com">http://www.alexgoretoy.com</a><br><a href="mailto:somebodywhocarez@gmail.com">somebodywhocarez@gmail.com</a><br>
<br><br><div class="gmail_quote">On Mon, Jan 5, 2009 at 8:14 PM, Grant Edwards <span dir="ltr"><<a href="mailto:grante@visi.com">grante@visi.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">On 2009-01-05, Kangkook Jee <<a href="mailto:aixer77@gmail.com">aixer77@gmail.com</a>> wrote:<br>
<br>
</div><div class="Ih2E3d">> I'd like to measure number of bytes sent(or recv'd) from my<br>
> python application. Does anyone have any idea how can I<br>
> achieve this?<br>
<br>
</div>Aside from tcpdump/wireshark, you can set up iptables rules to<br>
enable accounting for traffic based on IP addresses and ports.<br>
<br>
<a href="http://wiki.openvz.org/Traffic_accounting_with_iptables" target="_blank">http://wiki.openvz.org/Traffic_accounting_with_iptables</a><br>
<a href="http://www.faqs.org/docs/linux_network/x-087-2-accounting.ipfwadm.html" target="_blank">http://www.faqs.org/docs/linux_network/x-087-2-accounting.ipfwadm.html</a><br>
<a href="http://www.catonmat.net/blog/traffic-accounting-with-iptables/" target="_blank">http://www.catonmat.net/blog/traffic-accounting-with-iptables/</a><br>
<br>
--<br>
<font color="#888888">Grant<br>
</font><div><div></div><div class="Wj3C7c"><br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>