head.java public class head { public static void main(String[] args) throws InterruptedException { String tracerserver="http://127.0.0.1/eds/track.php";//tracker server address int timeRange=1;//in minutes System.out.println("Application running now...!"); while(true) { try { tracer machine = new tracer(); //System.out.println("Ip address: "+machine.ipaddr()); //System.out.println("Mac Address: "+machine.macAddr()); String requestParameters ="ip="+machine.ipaddr()+"&mac="+machine.macAddr()+"&point=3.223,2.93"; sender.sendGetRequest(tracerserver, requestParameters); Thread.sleep((timeRange*60000)); } catch(Throwable t) { System.err.println("Error:"+t); } } } } sender.java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.*; public class sender { public sender(){} public static String sendGetRequest(String endpoint, String requestParameters) { String result = null; if (endpoint.startsWith("http://")) { //Send a GET request to the servlet try { String urlStr = endpoint; if (requestParameters != null && requestParameters.length () > 0) { urlStr += "?" + requestParameters; } URL url = new URL(urlStr); URLConnection conn = url.openConnection (); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = rd.readLine()) != null) { sb.append(line); } rd.close(); result = sb.toString(); } catch (Exception e) { e.printStackTrace(); } } return result; } } tracer.java import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin; public class tracer { public tracer(){} public String ipaddr() { try { InetAddress localaddr = InetAddress.getLocalHost(); return localaddr.getHostAddress(); } catch(UnknownHostException e) { return "Can't detect localhost : " + e; } } public String macAddr() { try { InetAddress address = InetAddress.getLocalHost(); NetworkInterface ni = NetworkInterface.getByInetAddress(address); if (ni != null) { byte[] mac = ni.getHardwareAddress(); if (mac != null) { String aa = HexBin.encode(mac) ; String ab = ""; int a=0; int b=2; for (int i = 0; i < mac.length; i++) { ab+=aa.substring(a, b)+ ((i < mac.length - 1) ? "-" : "") ; a=a+2; b=b+2; } return ab; } else { return "Address doesn't exist or is not accessible."; } } else { return "Network Interface for the specified address is not found."; } } catch (UnknownHostException e) { e.printStackTrace(); } catch (SocketException e) { e.printStackTrace(); } return null; } }
Sir if you have done with it. kindly send me a code to my email id. i have tried but couldnt able to do it. my email id is <b>sana.asghar928@gmail.com</b> Sana Asghar thanks.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)