开发者

Get printer id in java

开发者 https://www.devze.com 2023-02-06 23:56 出处:网络
I have edited the question \"How can I get the serial no. or mac address of a printer dynamically through java.\" to \"How can I get the id of a pri开发者_如何学Pythonnter dynamically through java.\"

I have edited the question "How can I get the serial no. or mac address of a printer dynamically through java." to "How can I get the id of a pri开发者_如何学Pythonnter dynamically through java."


Please try this one ... I hope you find it helpful!

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();
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消