File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How grab/listen to all outgoing data (on a socket?)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How grab/listen to all outgoing data (on a socket?)?" Watch "How grab/listen to all outgoing data (on a socket?)?" New topic

How grab/listen to all outgoing data (on a socket?)?

Dan Bizman
Ranch Hand

Joined: Feb 25, 2003
Posts: 387
I know this is a broad question and I'm not even sure I'm stating it properly, but basically here's what I want to do:

1. There will be programs that attempt to open a connection to outside sources (like an email client)

2. I want all data that they send over that line to be readable by my program without need to alter those programs

Is it possible to listen on outgoing ports? For example, if I'm at and they try to send something to an outside computer at, how would I grab that "conversation"?
Henry Wong

Joined: Sep 28, 2004
Posts: 20517

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.

[ November 02, 2006: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Michael McHugh

Joined: May 30, 2006
Posts: 3
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.
I agree. Here's the link:
subject: How grab/listen to all outgoing data (on a socket?)?
It's not a secret anymore!