我正在开发一个充当服务器的Web应用程序。在这个应用程序中,我使用ServerSocket实现了服务器应用程序和充当客户端的wi-fi设备之间的双向通信。我没有直接连接到我的服务器,我正在连接到我的路由器,哪个端口转发到我的系统,双向通信成功。我现在想要的是找到连接的Wi-fi设备的MAC地址。我已经做了一些研究,并试图获得MAC地址,但失败了。任何人都可以帮助我做到这一点。以下是我的代码的一部分。如何找到连接到插座的Wi-Fi设备的MAC地址
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 the socket server at port:" +port);
boolean listeningSocket = true;
try {
Sersocket = new ServerSocket(port);
System.out.println("Waiting for 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();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
System.out.println(sb.toString());
我我正在获取我的PC的MAC地址而不是Wi-Fi设备。 – Arun