IPdump.java
资源名称:IPdump.rar [点击查看]
上传用户:ksyhspjx
上传日期:2022-08-06
资源大小:1k
文件大小:1k
源码类别:
网络编程
开发平台:
Java
- package bysj;
- import jpcap.*;
- import java.net.*;
- public class IPdump implements JpcapHandler
- {
- public void handlePacket(Packet packet){
- if (packet instanceof IPPacket) {
- System.out.println("协议类型:IP");
- IPPacket ipp = (IPPacket) packet;
- try {
- System.out.println("IPpacket: "+"ipVersion:"+ipp.version+" "+"iplen: "+ipp.length+" "
- +"iptos:"+ipp.rsv_tos+" "+"ipcaplen:"+ipp.caplen +" "+"ipident:"+ipp.ident);
- System.out.println(ipp.rsv_frag+" "+ipp.offset+" "+ipp.hop_limit+" "+ipp.protocol+" "+ipp.header+" "
- +ipp.src_ip+" -->"+ipp.dst_ip+" "+ipp.options);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public static void main(String[] args) throws java.io.IOException {
- String[] lists = Jpcap.getDeviceDescription();
- System.out.println("Start capturing on " + lists[0]);
- Jpcap jpcap = Jpcap.openDevice(Jpcap.getDeviceList()[0], 1000, false, 20);
- jpcap.loopPacket( -1, new IPdump());
- }
- }