我正在開發一個充當服務器的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