如题
解决方案 »
- 小弟初学,半夜睡不着写了一个测试this的程序,有大牛能详细阐述一下this关键字在方法中引用调用该方法的对象(注:多层调用)此时this指的到底是什么?
- 我的jsp文件运行不了
- 为什么这个聊天程序刚开始时的聊天内容不同步,而且刚开始时的内容还会丢失
- 菜鸟编的练练看 请大虾帮忙(2)
- int[]转换成byte[]在线等??
- 请教一个组合键的判断问题,如果判断ctrl+a这样的键盘事件呢?
- 还是关于阴阳历互转的问题,50分
- eclipse
- 请问String.equals()和String.equalsIgnoreCase()有什么区别啊?
- 有谁用过iText7,如何合并pdf?
- 关于JProgressBar的问题,急!!!
- 一个方法调用的问题.谢谢.
使用Runtime 和Process联合使用.
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.util.Vector;
import java.io.*;public class test {
public test() {
} Process p;
private 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;
}
}
private void Start(String shellCommand){
try{
if(p!=null){
p.destroy();
p=null;
}
Runtime sys= Runtime.getRuntime();
p=sys.exec(shellCommand);
}catch(Exception e){
System.out.println(e.toString());
}
}//取得网卡地址
private String getMacAddress(){
String cmd;
if (!System.getProperty("os.name").equals("Windows NT")){
cmd = new String("cmd.exe /c ipconfig /all");
}
else{
cmd = new String("command.com /c ipconfig /all");
}
Vector resultCmd = this.execute(cmd);
return parseCommand(resultCmd.toString());
} //从字符串中解析出所需要获得的字符串
private String parseCommand(String s){
String find = "Physical Address. . . . . . . . . :";
int findIndex = s.indexOf(find);
if (findIndex != -1)
return s.substring(findIndex + find.length() + 1,
findIndex + find.length() + 1 + 17);
else {
return "not find macAddress";
}
}
public static void main(String[] args) {
test test1 = new test();
System.out.print(test1.getMacAddress());
}}
import java.net.*;
public class NetTool{
InetAddress myIPaddress=null;
InetAddress myServer=null; public static void main( String args[]){ NetTool mytool;
mytool=new NetTool(); System.out.println("Your host IP is: "
+ mytool.getMyIP());
System.out.println("The Server IP is :"
+mytool.getServerIP()); } //取得LOCALHOST的IP地址
public InetAddress getMyIP() {
try { myIPaddress=InetAddress.getLocalHost();}
catch (UnknownHostException e) {}
return (myIPaddress);
}
//取得 www.abc.com 的IP地址
public InetAddress getServerIP(){
try {myServer=InetAddress.getByName(
"www.abc.com");}
catch (UnknownHostException e) {}
return (myServer);
} } ---- 由于JAVA语言的跨平台特性,以上程序编译后可直接在任何装有JVM系统的机器上运行。以上程序旨在抛砖引玉,读者可将上述代码稍加变换转化成APPLET加到你的homepage中,或将地址查询结果写到一个文件中去,建立自己本地的hosts文件。