ether.src_mac=device.mac_address;
ether.dst_mac=gwmac;
icmp.datalink=ether;
captor.setFilter("icmp and dst host "+thisIP.getHostAddress(),true);
JpcapSender sender=captor.getJpcapSenderInstance();
//JpcapSender sender=JpcapSender.openDevice(device);
sender.sendPacket(icmp);
while(true){
ICMPPacket p=(ICMPPacket) captor.getPacket();
//System.out.println("received "+p);
if(p==null){
System.out.println("Timeout");
}else if(p.type==ICMPPacket.ICMP_TIMXCEED){
p.src_ip.getHostName();
System.out.println(icmp.hop_limit+": "+p.src_ip);
icmp.hop_limit++;
}else if(p.type==ICMPPacket.ICMP_UNREACH){
p.src_ip.getHostName();
System.out.println(icmp.hop_limit+": "+p.src_ip);
System.exit(0);
}else if(p.type==ICMPPacket.ICMP_ECHOREPLY){
p.src_ip.getHostName();
System.out.println(icmp.hop_limit+": "+p.src_ip);
System.exit(0);
}else continue;
sender.sendPacket(icmp);
}
}