可能从Java获取客户端MAC地址? [英] possible to get the client mac address from java?

查看:104
本文介绍了可能从Java获取客户端MAC地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Java捕获客户端mac地址,ip详细信息.

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

我尝试了以下程序.但是它仅显示服务器ip详细信息.

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

我想访问客户端的Mac ID详细信息.任何帮助将不胜感激.

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

推荐答案

MAC地址不随TCP/IP(第3层及更高层)流量传输.MAC地址属于第2层,仅在单个LAN网段内有意义.

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.

在通常情况下,客户端和服务器位于不同的LAN网段中,无法在服务器上获取客户端的MAC地址.如果客户端和服务器位于同一LAN上,则可以通过查询本地ARP表来检索MAC,这可能需要提升的特权.

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.

这篇关于可能从Java获取客户端MAC地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆