import java.io.*; public class mac { public static void main(String[] args)throws Exception { Runtime r = Runtime.getRuntime(); Process p =r.exec(args[0]); BufferedReader read = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); String text; while( (text=read.readLine())!=null ) { System.out.println(text); } } } 在用正则表达式包java.util.regex,筛选一下就可以了。 java mac ipconfig
读取网卡等信息: public class NICid { public NICid() { } public static void main(String[] args) { NICid nicid= new NICid(); try { Process s = Runtime.getRuntime().exec( "c:\\windows\\system32\\ipconfig.exe /all");//注意这里是你的windows安装目录,也可以在这里判断windows的安装目录是winnt还是windows或其他 InputStreamReader ir = new InputStreamReader(s.getInputStream()); LineNumberReader input = new LineNumberReader(ir); String line; while ( (line = input.readLine()) != null) { System.out.println("message is ------>" + line); } } catch (IOException ex) { System.out.print(ex.getMessage()); } } }
这样也可以 import java.io.*; import java.io.*; public class mac { public static void main(String[] args)throws Exception { Runtime r = Runtime.getRuntime(); Process p =r.exec(args[0]); BufferedReader read = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); String text; int index;// 得到":"下标 int index2;//得到"."下标 while( (text=read.readLine())!=null ) { System.out.println(text); index = text.indexOf(":"); index2 = text.indexOf("."); if( index2 != -1) { String info = text.substring(0,index2-1); System.out.print(info); if( index != -1){ String ip = text.substring(text.indexOf(":")+1); System.out.println(ip); } } } } }
java不能实现
用本地方法调用c语言
http://expert.csdn.net/Expert/topic/2560/2560802.xml?temp=.3973047
否则可以调用C 里实现的DLL
public class mac
{
public static void main(String[] args)throws Exception
{
Runtime r = Runtime.getRuntime();
Process p =r.exec(args[0]);
BufferedReader read = new BufferedReader(
new InputStreamReader(
p.getInputStream()
)
);
String text;
while( (text=read.readLine())!=null )
{
System.out.println(text);
}
}
}
在用正则表达式包java.util.regex,筛选一下就可以了。
java mac ipconfig
public class NICid {
public NICid() {
} public static void main(String[] args) {
NICid nicid= new NICid();
try {
Process s = Runtime.getRuntime().exec(
"c:\\windows\\system32\\ipconfig.exe /all");//注意这里是你的windows安装目录,也可以在这里判断windows的安装目录是winnt还是windows或其他
InputStreamReader ir = new InputStreamReader(s.getInputStream()); LineNumberReader input = new LineNumberReader(ir); String line; while ( (line = input.readLine()) != null) { System.out.println("message is ------>" + line); }
}
catch (IOException ex) {
System.out.print(ex.getMessage());
}
}
}
import java.io.*;
import java.io.*;
public class mac
{
public static void main(String[] args)throws Exception
{
Runtime r = Runtime.getRuntime();
Process p =r.exec(args[0]);
BufferedReader read = new BufferedReader(
new InputStreamReader(
p.getInputStream()
)
);
String text;
int index;// 得到":"下标
int index2;//得到"."下标
while( (text=read.readLine())!=null )
{
System.out.println(text);
index = text.indexOf(":");
index2 = text.indexOf(".");
if( index2 != -1)
{
String info = text.substring(0,index2-1);
System.out.print(info);
if( index != -1){
String ip = text.substring(text.indexOf(":")+1);
System.out.println(ip);
}
}
}
}
}