7

I'm wondering how to go about monitoring network traffic on my Mac. Like the way activity monitor does it, showing the bytes / packets in and out.

I know it's a bit vague, but I'm unsure of the best place to start.

EDIT: I'm wanting to do this in code, not use an existing piece of software.

Tom Irving
  • 10,041
  • 6
  • 47
  • 63
  • See the Mac OS X-related answer to this question: http://stackoverflow.com/questions/1126790/how-to-get-network-adapter-stats-in-linux-mac-osx (i.e. use sysctl). – Jakob Borg Apr 18 '10 at 14:01

4 Answers4

6

I just found the open source project, MenuMeters. It's got exactly what I'm looking for.

Tom Irving
  • 10,041
  • 6
  • 47
  • 63
3

You may want to look into programming with pcap. That's the library which drives tcpdump.

Josh
  • 10,961
  • 11
  • 65
  • 108
0

There are lot of paid & freeware applications. But if you a command line person like me, Try this:

nettop //displays network usage per application with lot of details
nettop (press h) //displays help menu
nettop (press c) //collapse and display brief info on network usage
Sairam Krish
  • 10,158
  • 3
  • 55
  • 67
0

Use tcpdump for quick-n-dirty low-level command-line monitoring, and wireshark for the kitchen sink.

OTOH, if you just want to know the number of bytes/packets (as opposed to their contents), try Net Monitor, which is commercial, unfortunately.

titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365