How to read the motherboard serial number, hard disk serial number, or MAC address in JAVA

Source: Internet
Author: User

From: http://ywh5.bokee.com/viewdiary.13113717.html

 

Private string getphysicaladdress (){
String cmd = "cmd.exe/C ipconfig/all ";
String strrs = "";
String result = "";
Strrs = executesyscmd (CMD );
Result = parsecmd (strrs );
Return result;
}

 

Private string executesyscmd (string shellcommand ){
Try {
Start (shellcommand );
Stringbuffer sb = new stringbuffer ();
Datainputstream in = new datainputstream (P. getinputstream ());
Bufferedreader reader = new bufferedreader (New inputstreamreader (in ));
String line;
Do {
Line = reader. Readline ();
If (line = null ){
Break;
}
Else {
Sb. append (line );
}
}
While (true );
Reader. close ();
Return sb. toString ();
}
Catch (exception e ){
// Error
Return NULL;
}
}

Private string parsecmd (string s ){
String find = "physical address .........:";
Int findindex = S. indexof (FIND );
If (findindex =-1)
Return "not find ";
Else
Return s. substring (findIndex + find. length () + 1,
FindIndex + find. length () + 1 + _ physicalLength );
}

You can reference this article through this link: http://ywh5.bokee.com/tb. B? DiaryId = 13113717

I have posted this article !! Come back in the evening to verify the correctness !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.