In terms of tools, you can use a commandline tool call "tcpdump" which will provide and filter all the traffic going on with a network card. The windows version of that tool is "windump". There is also a higher level tool, called "ethereal", which provides a GUI interface to "tcpdump" and "windump".
Now... In terms of APIs, these packages also have lower level libraries for applications to use. And I have seen some mention of a Java API around these libraries. I have *never* used "tcpdump" in a programmatic fashion, so don't have an opinion on the libraries.
But the "tcpdump", "windump", and "ethereal" tools, works as advertised and is great for debugging network programs.
Henry [ November 02, 2006: Message edited by: Henry Wong ]
The tools listed above are all based on the same packet capture library, Libpcap (and it's Windows port, Winpcap). There are Java wrappers available for these libraries that you can use. The two that I know of are jpcap and Jpcap (same name, different projects). These provide an API to let you grab all traffic on the network, or filter based on destination address, port, protocol, etc.