Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java TCP Socket Sniffing

I am using TCP sockets to communicate data between a server and client program using a specific port number on the same computer (localhost).

I need a software that can capture the data being sent/received through that socket?

(or)

What's the simplest way of sniffing packets from a specified port in Java?

like image 240
user57175 Avatar asked Feb 26 '09 13:02

user57175


2 Answers

I suggest using Wireshark. It's easy to use and runs on many platforms.

http://www.wireshark.org/

like image 183
Lennart Koopmann Avatar answered Sep 22 '22 00:09

Lennart Koopmann


If you are up to some coding (and not just running the wireshark/tcpdump) then you have few choices. If you want stick to Java, then the only (?) option to use raw sockets is via JNI and there are few libraries that can help, for example:

  • jNetPcap - wrapper around the native libpcap/winpcap libraries, exposing all of their functions and structures
  • RockSaw - API for using raw sockets
like image 21
Anonymous Avatar answered Sep 20 '22 00:09

Anonymous