Pages

March 08, 2012

how to detect broadcast ip in java


how to detect broadcast ip in java

 How to detect Denial of Service attack

The project need jpcap.

import jpcap.*;
import jpcap.packet.ARPPacket;
import jpcap.packet.Packet;

class Tcpdump implements PacketReceiver {
public void receivePacket(Packet packet) {
if (packet instanceof ARPPacket) {
System.out.println(packet);
ARPPacket arp=(ARPPacket)packet;
// System.out.println(arp.hardtype=ARPPacket.HARDTYPE_ETHER);
// System.out.println(arp.prototype=ARPPacket.PROTOTYPE_IP);
// System.out.println(arp.prototype=ARPPacket.PROTOTYPE_IP);
// System.out.println(arp.operation=ARPPacket.ARP_REQUEST);
System.out.println("sender hardware address ----->" +arp.getSenderHardwareAddress());
System.out.println("Sender protocol address ----->"+arp.getSenderProtocolAddress());
System.out.println("target hardware address ----->"+arp.getTargetHardwareAddress());
System.out.println("target protocol address ----->"+arp.getTargetProtocolAddress());
System.out.println(" arp reply (short) ----->"+ arp.ARP_REPLY);
System.out.println(" arp request (short) ----->"+arp.ARP_REQUEST);
// System.out.println(" arp caplen (int) ----->"+arp.caplen);
// System.out.println(" arp hardtype (short) ----->"+arp.hardtype);
// System.out.println(" arp hlen (short) ------>"+arp.hlen);
// System.out.println(" arp packetlength (int) ------>"+arp.len);
// System.out.println(" arp operation (short) ----->"+arp.operation);
// System.out.println(" arp plen (short) ------>"+arp.plen);
// System.out.println(" arp prototype (short) ------>"+arp.prototype);
// System.out.println(" arp second (long) ------>"+arp.sec);
// System.out.println(" arp usec (long) ------>"+arp.usec);
// System.out.println(" arp hashcode (int) ------>"+arp.hashCode());
// System.out.println(" arp to string ------>"+ arp.toString());
// System.out.println(" arp hardtype ether(short) ------>"+arp.HARDTYPE_ETHER);
// System.out.println(" arp frame relay (short) ------>"+arp.HARDTYPE_FRAMERELAY);
// System.out.println(" arp hardtype ieee802(short) ---->"+arp.HARDTYPE_IEEE802);
// System.out.println(" arp inv reply (short)----->"+arp.INV_REPLY);
// System.out.println(" arp inv request (short)----->"+arp.INV_REQUEST);
// System.out.println(" arp prototype ip (short) ---->"+arp.PROTOTYPE_IP);
// System.out.println(" arp rarp reply (short)----->"+arp.RARP_REPLY);
// System.out.println(" arp rarp request (short)----->"+ arp.RARP_REQUEST);
// System.out.println(" arp data (byte[])---->"+arp.data);
// System.out.println(" arp datalink ( datalink)----->"+arp.datalink);
// System.out.println(" arp header (byte[]) ----->"+arp.header);
// System.out.println(" arp sender hardaddress (byte[])---->"+arp.sender_hardaddr);
// System.out.println(" arp sender proto address (byte[]) ---->"+arp.sender_protoaddr);
// System.out.println(" arp target hard address (byte[])---->"+arp.target_hardaddr);
// System.out.println(" arp target proto address (byte[])----->"+arp.target_protoaddr);
// System.out.println(" arp get class (class) ----->"+arp.getClass());
// System.out.println(" arp end of file ---->"+arp.EOF);
System.out.println(" ******************************************************* ");
String s=arp.getSenderProtocolAddress().toString();
System.out.println("string" +s);
if(s.endsWith("1"))
{
int l=s.length();
String sub=s.substring(1,l);
System.out.println(" sub string(ipaddr)"+sub);
}

System.out.println(" ******************************************************* ");



// arp.hlen=6;
// arp.plen=4;

}
}

public static void main(String[] args) throws Exception {
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
// if(args.length<1){
// System.out.println("usage: java Tcpdump

No comments:

Post a Comment

Your feedback may help others !!!