用java写个嗅探程序,思路和需要哪些中间插件

解决方案 »

  1.   


    LZ结贴率102.27是怎么做到的....O_O!你准备嗅探什么?
      

  2.   

    用java写个嗅探程序,思路和需要哪些中间插件?楼主,您想嗅探什么东东啊 
      

  3.   

    jpcappackage com;import java.io.IOException;import jpcap.JpcapCaptor;
    import jpcap.NetworkInterface;
    public class Test {
    public static void getAllDevice() throws IOException{
    NetworkInterface[] advices =  JpcapCaptor.getDeviceList();
    for (int i = 0; i < advices.length; i++)
    System.out.println(i + ":" + advices[i].name+ getString((advices[i].mac_address))+ "("
    + advices[i].description + ")");
    JpcapCaptor cap = JpcapCaptor.openDevice(advices[1], 200000, false, 3000);
    cap.setFilter("tcp", true);
    cap.processPacket(1, new Myprocess());
    //Packet packet = cap.getPacket();

    //System.out.println(bytes);
    }
     
    public static void main(String[] a){
    System.out.println(7<<4);
    System.out.println("获得网络设备如下:");
    try {
    getAllDevice();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    public static String getString(byte[] b){
    String mak ="";
    for(int i = 0;i<b.length;i++){
    //System.out.println(b[i]);
    String mac_hex16 = Integer.toHexString(b[i]&0xff);
    if(mac_hex16.length()!=2){
    mac_hex16="0"+mac_hex16;
    }
    //System.out.println(mac_hex16);
    mak=mak+mac_hex16+":";
    }
    System.out.println(mak);
    return mak;
    }
    }Myprocess.javapackage com;import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.math.BigInteger;import com.sun.org.apache.xerces.internal.impl.dv.xs.IntegerDV;import jpcap.PacketReceiver;
    import jpcap.packet.Packet;public class Myprocess implements PacketReceiver { public void receivePacket(Packet packet) {
    // byte[] byts = p.data;
    try{
    byte[] bytes = packet.data ;
    // for(int a = 0 ;a<bytes.length;a++)
    // {
    // System.out.println(Integer.toBinaryString(Integer));
    // }
    BigInteger bi = new BigInteger(bytes);
    System.out.println(bi.toString(2));
    System.out.println(packet);
    FileOutputStream fw = new FileOutputStream(new File("C://date.dat"),false);
    BufferedOutputStream bo = new BufferedOutputStream(fw);
    bo.write(bytes);
    bo.flush();
    bo.close();
    System.out.println(new String(bytes));
    }catch(Exception e){} }}