简体   繁体   中英

possible to get the client mac address from java?

I want to capture client mac address,ip details from java.

I tried following program.But it shows only server ip details.

InetAddress ip;
    try {

        ip = InetAddress.getLocalHost();
        System.out.println("Current IP address : " + ip.getHostAddress());

        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) ? "-" : ""));
        }

I want to access client mac id details.Any help will be appreciated.

A MAC address is not transmitted with TCP/IP (layer 3 and above) traffic. MAC addresses belong at layer 2 and are meaningful only within a single LAN segment.

In the general case of client and server being on different LAN segments there is no way to get the client's MAC address at the server. If client and server are on the same LAN then you might be able to retrieve the MAC by querying the local ARP tables, which would probably require elevated privileges.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM