jpcap
TRANSCRIPT
JAVA(Networking)
(Jpcap: Capturing and displaying packet traffic with
JpcapCapturePacket and receivePacket)JPCAP:
Jpcap is an open source network packet capture library based
on the libpcap and winpcap libraries that you can use with java to
capture and display network traffic on Linux, Windows and Macintosh
computers. Jpcap capture Ethernet, TCP, UDP, IPv4, IPv6, ARP/RARP,
and TCMPv4 packets and analyzes each packet’s header and data
payload.
USING JPCAP:
There are several dependencies and requirements you will need
to meet before being able to use Jpcap in your Java project. To write
Java application using Jpcap you will need to:
1. Download and install winpcap:
Link=http://www.winpcap.org/install/default.html
2. Download and install Jpcap: Link=
http://netresearch.ics.uci.edu.kfhjiii/jpcap/doc/index.html
The default install routine for Jpcap may not put things in the
right place for you particular development environment.
Therefore, after installing Jpcap to extract the files find “Jpcap.dll”
and “Jpcap.jar” on your system.
3. Copy “Jpcap.dll” into “[JRE directory]\bin or [JRE directory]\lib\ext\
x86”
4. Copy “Jpcap.jar” into “[JRE directory]\bin or [JRE directory]\lib\
ext”
5. Copy “Jpcap.jar” into “[JRE directory]\bin or [JRE directory]\jre\lib\
ext”
(Note: if you have the 64bit JDK an JRE and download the 32bit
version, you will need copy the files to that Platform’s and JDK
folder as well)
6. If are using the 64bit JDK and JRE, download and use the 32 bit
JDK and JRE. If you using Netbean you can add it as an additional
platform and select between 32 and 64 bit version when
necessary.
7. If you using Netbean, right-click on project “Property” and select
“Libraries”. Then select the 32-bit JDK from Java Platform
dropdown list.
8. Click the “JAR/Folder” button under project “Properties” and
“Libraries” and add the “jpacp.jar” file in to your project.
9. When running Applications that use Jpcap you need ROOT
privileges in Linux and Administrative privileges in Windows. You
will get run-time error if you attempt to you Jpcap without the
appropriate privileges. If you using Netbean in Window, rt-click
and choose “Run as Administrator”. In linux, you can hit ALT+F2
and type “gksudo Netbeans”.
10. All done! Now you can start coding project using Jpcap
Here are some Jpcap class we will be using:
1. Packet= a Jpcap class that is instantiabed for each packet
capture and used to access that packet’s field information and
data.
2. JpcapCaptor= a Jpcap class with many methods for capturing
and filtering packets.
Here are some method Jpcap functions we will be using:
1. getDeiviceList()= return an array of NetworkInterface objects
for each network interface on the specified.
2. openDevice()= opens the specified network interface. It’s
argument are: 1= network interface to open, 2= max # bytes
captured at once, 3= promiscuous node (true or false), 4= time
out for capture.
3. setFilter()= set port filter options. Take 2 argument: 1= String
of to filter, 2= optimize(true or false).
4. loopPacket()=captures packets for specified # of itearions.
Take 2 arguments: 1= # capture (-1=infinite), 2= new instance
of a class that implements the PacketReceiver interface.
IGNORES timeout and does NOT support “non-blocking” mode.
5. processPacket()= captures packets for specified # of iterations.
Take 2 arguments: 1= #capture(-1=infinite), 2= new instance of
a class that implement the PacketReceiver interface. ACCEPT
timeout and SUPPORT “non-blocking” mode(return immediately
when there’s nothing to capture).
6. getPacket()= capture a single packet.
7. breakLoop()= force loopPacket and processPacket to stop
looping and return.
8. setPacketReadTimeout()= set the timeout values.
9. getPacketReadTiomeout()= retrieves the timeout values.