2011-01-28 78 views
1

我編輯了問題「如何通過java動態獲取打印機的序列號或mac地址」。到「如何通過Java動態獲取打印機的ID」。在java中獲取打印機ID

回答

2

請嘗試這一個...我希望你覺得它有幫助!

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

在這個例子中,我們應該使用系統的IP地址,並獲得所有連接的h/w。對? – 1355 2011-01-28 05:02:55