【问题标题】:Get printer id in java在java中获取打印机ID
【发布时间】:2011-01-28 04:45:58
【问题描述】:

我已经编辑了“如何通过 java 动态获取打印机的序列号或 MAC 地址”的问题。到“如何通过java动态获取打印机的ID。”

【问题讨论】:

    标签: java printers hardware-id


    【解决方案1】:

    请试试这个...希望对您有所帮助!

    public class MacAdd {
    
        public static void main(String[] args) {
            try {
    
                InetAddress add = InetAddress.getByName("192.168.46.53");
    
    
                NetworkInterface ni1 = NetworkInterface.getByInetAddress(add);
                if (ni != null) {
                    byte[] mac1 = ni1.getHardwareAddress();
                    if (mac1 != null) {
    
                        for (int k = 0; k < mac.length; k++) {
                            System.out.format("%02X%s", mac[k], (i < mac.length - 1) ? "-" : "");
                        }
                    } else {
                        System.out.println("Address doesn't exist ");
                    }
                } else {
                    System.out.println("address is not found.");
                }
            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (SocketException e) {
                e.printStackTrace();
            }
        }
    }
    

    【讨论】:

    • 在示例中,我们应该使用系统的 IP 地址并获取所有已连接的硬件。对吗?
    • 我得到的答案是“00-24-8C-C7-EC-DC”。会是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 2011-03-29
    相关资源
    最近更新 更多