j2se5.0 a new feature of Windows read the physical address of the network card

Source: Internet
Author: User
Tags stringbuffer

This example uses the j2se5.0 Processbuilder class to perform an external program, which is more convenient than the runtime.exec and can set environment variables. Package com.kuaff.jdk5package;

Import java.io.IOException;
Import Java.io.InputStream;
Import java.util.ArrayList;
Import java.util.List;

public class Processbuildershow
{
public static list<string> getphysicaladdress ()
{
Process p = null;
Physical network card list
list<string> address = new arraylist<string> ();

Try
{
Execute Ipconfig/all command
p = new Processbuilder ("ipconfig", "/all"). Start ();
}
catch (IOException E)
{
return address;
}
Byte[] B = new byte[1024];
StringBuffer sb = new StringBuffer ();
Reading process output values
InputStream in = P.getinputstream ();
Try
{
while (In.read (b) >0)
{
Sb.append (New String (b));
}
}
catch (IOException E1)
{
}
Finally
{
Try
{
In.close ();
}
catch (IOException E2)
{
}
}
The following analysis outputs the value, obtains the physical network card
String rtvalue = sb.substring (0);
int i = Rtvalue.indexof ("Physical address. ........:");
while (i>0)
{
Rtvalue = rtvalue.substring (i + "Physical address. ........:".length());
Address.add (rtvalue.substring (0,18));
i = Rtvalue.indexof ("Physical address. ........:");
}

return address;

}
public static void Main (string[] args)
{
list<string> address = processbuildershow.getphysicaladdress ();
for (String add:address)
{
System.out.printf ("Physical network card address:%s%n", add);
}
}
}

Related Article

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.