http://www.cn-java.com/target/news.php?news_id=1053
解决方案 »
- action跳转保持参数和地址栏问题
- 一个现实问题,累了过来看看!
- 谁有《How Tomcat Work》代码?
- 怎样生成一个——14位时间+6位随机数——组成的20位数??顶有分
- java中二进制与十进制如何转换?
- 写了一个jsp程序,运行之后中文显示的是乱码.这是怎么回事??给出代码和运行情况如下:
- 请问用jsp如何使地址栏里的网页地址匿名
- 请问怎么样在Apache中调用Servlet?
- 关于把连接oracle的bean改为连接mysql的问题。
- JQuery 页面加载时,append无法加入HTML!?求解
- JSP,小鳥提問!
- 怎么从远程SQLServer数据库中把数据插入本地数据库JAVA实现????
import java.io.*;
import java.util.*;
public class Util_syscmd{ /**
* @param shellCommand
*
*/
public Vector execute(String shellCommand){
try{
Start(shellCommand);
Vector vResult=new Vector();
DataInputStream in=new DataInputStream(p.getInputStream());
BufferedReader reader=new BufferedReader(new InputStreamReader(in)); String line;
do{
line=reader.readLine();
if (line==null){
break;
}
else{
vResult.addElement(line);
}
}while(true);
reader.close();
return vResult; }catch(Exception e){
//error
return null;
}
}
/**
* @param shellCommand
*
*/
public void Start(String shellCommand){
try{
if(p!=null){
kill();
}
Runtime sys= Runtime.getRuntime();
p=sys.exec(shellCommand);
}catch(Exception e){
System.out.println(e.toString());
}
}
/**
kill this process
*/
public void kill(){
if(p!=null){
p.destroy();
p=null;
}
}
Process p;
}
import java.io.*;
import java.util.*;class GetPhysicalAddress{
//网卡物理地址长度
static private final int _physicalLength =16;
public static void main(String[] args){
//output you computer phycail ip address
System.out.println(getPhysicalAddress());
}
static public String getPhysicalAddress(){
Util_syscmd shell =new Util_syscmd();
String cmd = "cmd.exe /c ipconfig/all";
Vector result ;
result=shell.execute(cmd);
return parseCmd(result.toString());
}
//从字符串中解析出所需要获得的字符串
static 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);
}
}