Java os PhysicalAddress


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Properties;

public class WindowsTools
{
	public static void main(String[] args) throws Exception
	{
		System.out.println(WindowsTools.getPhysicalAddress());
	}

	public static String getPhysicalAddress() throws Exception
	{
		Process p = Runtime.getRuntime().exec("cmd /c ipconfig -all");
		BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));

		String line;
		Properties props = System.getProperties();

		System.out.println(props.getProperty("os.name"));

		if ("Windows XP".equals(props.getProperty("os.name")))
		{
			while ((line = br.readLine()) != null && line.length() != 22)
			{
			}
			while ((line = br.readLine()) != null && line.length() != 61)
			{
			}
			return line.substring(61 - 17, 61);
		} else
		{

			return "";
		}
	}
}

你可能感兴趣的:(java,c,windows,OS,XP)