================= Client ===================
import java.io.*;
import java.net.*;
public class Client {
public static void main(String args[])
{
try
{
Socket sck = new Socket("localhost",3031);
// To send data to server
OutputStream os = sck.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println("01-00-5e-7f-ff-fa");
// To receive data from server
InputStream is = sck.getInputStream();
DataInputStream dis = new DataInputStream(is);
String msg = dis.readLine();
System.out.println(msg);
sck.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
======================= Server =========================
import java.io.*;
import java.net.*;
import java.util.*;
public class Server {
public static void main(String args[])
{
try
{
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("arp -a");
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = input.readLine();
line = input.readLine();
line = input.readLine();
ServerSocket ss = new ServerSocket(3031);
Socket sck = ss.accept();
// To receive data from client (Ethernet address)
InputStream is = sck.getInputStream();
DataInputStream dis = new DataInputStream(is);
String data = dis.readLine();
while((line=input.readLine())!=null)
{
// Creating array with the help of " " (space separator)
StringTokenizer st1 = new StringTokenizer(line," ");
while(st1.hasMoreElements())
{
String ipadrs = st1.nextElement().toString();
String phyadrs = st1.nextElement().toString();
String status = st1.nextElement().toString();
if (data.equals(phyadrs))
{
OutputStream os = sck.getOutputStream();
PrintStream ps = new PrintStream(os);
ps.println(" Your IP address is " + ipadrs);
}
}
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
Comments
Post a Comment