java - How to find the MAC address of Wi-Fi devices connected to socket -
i developing web application acts server. in application have implimented serversocket 2 way communication between server application , wi-fi device acts client. not connecting server directly, connecting router port forwards system , 2 way communication successful. want find mac address of wi-fi device connected.i have done research , tried mac address failed.can me on this.below part of code.
public class schedulejob extends servletapp implements job{ private int port = 1717; public static string number; string receiveddata = ""; public void execute(jobexecutioncontext context)throws jobexecutionexception { system.out.println("starting ... "); serversocket sersocket = null; system.out.println("starting socket server @ port:" +port); boolean listeningsocket = true; try { sersocket = new serversocket(port); system.out.println("waiting clients..."); } catch (ioexception e) { system.err.println("could not listen on port: 1717"); } try { while (listeningsocket) { socket scokt = sersocket.accept(); inetaddress machineadd = scokt.getinetaddress(); system.out.println("response-----:" +machineadd); inetaddress ip = inetaddress.getlocalhost(); system.out.println("current ip : "+ip); networkinterface network = networkinterface.getbyinetaddress(ip); byte[] mac = network.gethardwareaddress(); system.out.print("current mac address : "); stringbuilder sb = new stringbuilder(); (int = 0; < mac.length; i++) { sb.append(string.format("%02x%s", mac[i], (i < mac.length - 1) ? "-" : "")); } system.out.println(sb.tostring());
mac address piece of information belongs layer 2 of osi model.
in other words it's not preserved whenever communicating using l3 protocol (until communicating directly via cross cable or via l2 switch).
i recommend send mac address part of application communication client server, not lost when router port forwarding.
some of asked questions on topic:
Comments
Post a Comment