मैं एक समस्या हो रही थी अनुवर्ती कोड का उपयोग कर this question में एक मशीन है, जो हल किया गया था के मैक पते पाने के लिए जावा में मैक पते प्राप्त करें:का उपयोग कर getHardwareAddress गैर नियतात्मक
Process p = Runtime.getRuntime().exec("getmac /fo csv /nh");
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()));
String line;
line = in.readLine();
String[] result = line.split(",");
System.out.println(result[0].replace('"', ' ').trim());
हालांकि, मैं चाहते हैं पता है कि यह कोड क्यों काम नहीं कर रहा है। हर बार जब यह मैक पता पढ़ता है तो यह एक अलग मूल्य देता है। सबसे पहले मैंने सोचा कि ऐसा इसलिए था क्योंकि GetHash, शायद एक टाइमस्टैम्प का उपयोग करके मुझे पता नहीं है ... लेकिन इसे भी परिणाम परिवर्तन को हटा रहा है।
कोड
public static byte[] getMacAddress() {
try {
Enumeration<NetworkInterface> nwInterface = NetworkInterface.getNetworkInterfaces();
while (nwInterface.hasMoreElements()) {
NetworkInterface nis = nwInterface.nextElement();
if (nis != null) {
byte[] mac = nis.getHardwareAddress();
if (mac != null) {
/*
* Extract each array of mac address and generate a
* hashCode for it
*/
return mac;//.hashCode();
} else {
Logger.getLogger(Utils.class.getName()).log(Level.WARNING, "Address doesn't exist or is not accessible");
}
} else {
Logger.getLogger(Utils.class.getName()).log(Level.WARNING, "Network Interface for the specified address is not found.");
}
return null;
}
} catch (SocketException ex) {
Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
आउटपुट उदाहरण (मैं बाइट सरणी से सीधे मुद्रण कर रहा हूँ, लेकिन इसके लिए पर्याप्त है कि विभिन्न मुझे लगता है कि देखने के लिए) पहले से
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
[[email protected]
धन्यवाद
आप डिफ़ॉल्ट 'एक बाइट सरणी के toString' मुद्रण कर रहे हैं। –