java - Pinging an IP to receive a ping -


i need make program sends ping, or information string "check" ip addresses on network, , info ip if client active. want receive tells client other client working , operating normally. i'm not sure on how send information network locations without sending ping location doesn't exist. also, how can find out ip sending information main client? example, want send "check" main client locations on network, , if there computers on network other client, receive "check" , send "ok" ip. school project, , teacher confusing me. nothing tried far working @ all.

either u can use socket programming in java or can use jpcap library sending packets. jpcap sample code send packet.

import java.net.inetaddress;  import jpcap.*; import jpcap.packet.ethernetpacket; import jpcap.packet.ippacket; import jpcap.packet.tcppacket;  class sendtcp { public static void main(string[] args) throws java.io.ioexception{ networkinterface[] devices = jpcapcaptor.getdevicelist(); if(args.length<1){ system.out.println(“usage: java senttcp <device index (e.g., 0, 1..)>”); for(int i=0;i<devices.length;i++) system.out.println(i+”:”+devices[i].name+”(“+devices[i].description+”)”); system.exit(0); } int index=integer.parseint(args[0]); jpcapsender sender=jpcapsender.opendevice(devices[index]);  tcppacket p=new tcppacket(12,34,56,78,false,false,false,false,true,true,true,true,10,10); p.setipv4parameter(0,false,false,false,0,false, false,false,0,1010101,100,ippacket.ipproto_tcp, inetaddress.getbyname(“www.microsoft.com”), inetaddress.getbyname(“www.google.com”)); p.data=(“data”).getbytes();  ethernetpacket ether=new ethernetpacket(); ether.frametype=ethernetpacket.ethertype_ip; ether.src_mac=new byte[]{(byte)0,(byte)1,(byte)2,(byte)3,(byte)4,(byte)5}; ether.dst_mac=new byte[]{(byte)0,(byte)6,(byte)7,(byte)8,(byte)9,(byte)10}; p.datalink=ether;  for(int i=0;i<10;i++) sender.sendpacket(p); } } 

sample program receive packet.

import jpcap.*; import jpcap.packet.packet;  class tcpdump implements packetreceiver { public void receivepacket(packet packet) { system.out.println(packet); }  public static void main(string[] args) throws exception { networkinterface[] devices = jpcapcaptor.getdevicelist(); if(args.length<1){ system.out.println(“usage: java tcpdump <select number following>”);  (int = 0; < devices.length; i++) { system.out.println(i+” :”+devices[i].name + “(” + devices[i].description+”)”); system.out.println(” data link:”+devices[i].datalink_name + “(” + devices[i].datalink_description+”)”); system.out.print(” mac address:”); (byte b : devices[i].mac_address) system.out.print(integer.tohexstring(b&0xff) + “:”); system.out.println(); (networkinterfaceaddress : devices[i].addresses) system.out.println(” address:”+a.address + ” ” + a.subnet + ” ” + a.broadcast); } }else{ jpcapcaptor jpcap = jpcapcaptor.opendevice(devices[integer.parseint(args[0])], 2000, false, 20);  jpcap.looppacket(-1, new tcpdump()); } } } 

reference taken link


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -