下面一段代码是获取操作系统类型并获取系统IP地址的代码:
- String os = System.getProperty("os.name").toLowerCase();
- boolean b;
- if( os.startsWith("windows") )
- {
- b = true;
- }
- else if( os.startsWith("linux") )
- {
- b = false;
- }
- else
- {
- throw new IOException("Unknown operating system: "+os);
- }
- InputStream is;
- if( b )
- {
- is = Runtime.getRuntime().exec("ipconfig /all").getInputStream();
- }
- else
- {
- is = Runtime.getRuntime().exec("/sbin/ifconfig").getInputStream();
- }