java简单问题,高分求解(100分) 直接调用windowsAPI吧,估计可以 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我才打算开始学习java来取点经!!谢谢! 看看这个中不:import java.io.*;public class ReadMACAddress{ public static void main(String[] arg){ try{ java.lang.Process proc = Runtime.getRuntime().exec("ipconfig /all"); InputStream istr = proc.getInputStream(); byte[] data = new byte[1024]; istr.read(data); String netdata = new String(data); System.out.println("Your Mac Address="+procAll(netdata)); } catch(IOException e){ System.out.println("error="+e); } } public static String procAll(String str){ return procStringEnd(procFirstMac(procAddress(str))); } public static String procAddress(String str){ int indexof = str.indexOf("Physical Address"); if(indexof>0) return str.substring(indexof,str.length()); return str; } public static String procFirstMac(String str){ int indexof = str.indexOf(":"); if(indexof>0) return str.substring(indexof+1,str.length()).trim(); return str; } public static String procStringEnd(String str){ int indexof = str.indexOf("\r"); if(indexof>0) return str.substring(0,indexof).trim(); return str; }} 楼主可以介绍一下你的CMD.EXE /C IPCONFIG /ALL是在哪里执行的吗?你又是如何获取ipconfig返回的信息的呢?你取到返回的信息,应该是将ipconfig的输出重定向了吧?但既然是重定向为何cmd窗口又会出现呢? ipconfig是dos界面的程序,执行的时候会打开cmd窗口进行输入和输出。如果将输入和输出流截取,改变输出目标,应该可以不显示窗口。 private String getPhysicalAddress() { String cmd = "cmd.exe /c ipconfig/all"; String strRs=""; String result=""; strRs=executeSysCMD(cmd); result = parseCmd(strRs); return result; } private String executeSysCMD(String shellCommand) { try { Start(shellCommand); StringBuffer sb = new StringBuffer(); DataInputStream in = new DataInputStream(p.getInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; do { line = reader.readLine(); if (line == null) { break; } else { sb.append(line); } } while (true); reader.close(); return sb.toString(); } catch (Exception e) { //error return null; } } 你这应该是BS结构的程序啊java在server端执行应该获得的是server的MAC才对啊怎么会是Client的呢 public static String procStringEnd(String str){int indexof = str.indexOf("\r");if(indexof>0)return str.substring(0,indexof).trim();return str;}不太明白,为什么需要两句return? zyg158((DD)One-Time Password System)不好意思,没看清楚:) to jxncligang:没看到第一个return上面的if吗? 还是没有搞定.回答一下 zyg158((DD)One-Time Password System)的问题.这个实际上是用ORACLE FORM BUILDER开发的WEB程序,为了取得MAC,所以追加了数字签名等处理.但是,现在不管是B/S的还是WEB程序,都是出现以上情况的.包括在JBUILDER中都是出现的. 直接IPCONFIG /ALL何须cmd执行 帮忙看看java简单工厂模式计算机? Hibernate更新数据,报错,求教大侠指点,万分感谢 javabean的概念 applet中的音视频端口问题 请教java UI组件的命名规则? 一个parseFloat(String str)的问题 帮我调试一个简单的小程序 为什么这样发邮件发不出去阿?请教高手 想要美化界面,该怎么办? java里怎么导入声音?是什么类型的文件?? 简单问题1:接口可不可以实现接口? 我用bat文件执行java程序,我在里面set了classpath,可是执行的时候说的太长了,怎么解决?
来取点经!!
谢谢!
import java.io.*;public class ReadMACAddress{
public static void main(String[] arg){
try{
java.lang.Process proc = Runtime.getRuntime().exec("ipconfig /all");
InputStream istr = proc.getInputStream();
byte[] data = new byte[1024];
istr.read(data);
String netdata = new String(data);
System.out.println("Your Mac Address="+procAll(netdata));
}
catch(IOException e){
System.out.println("error="+e);
}
}
public static String procAll(String str){
return procStringEnd(procFirstMac(procAddress(str)));
} public static String procAddress(String str){
int indexof = str.indexOf("Physical Address");
if(indexof>0)
return str.substring(indexof,str.length());
return str;
}
public static String procFirstMac(String str){
int indexof = str.indexOf(":");
if(indexof>0)
return str.substring(indexof+1,str.length()).trim();
return str;
}
public static String procStringEnd(String str){
int indexof = str.indexOf("\r");
if(indexof>0)
return str.substring(0,indexof).trim();
return str;
}
}
String cmd = "cmd.exe /c ipconfig/all";
String strRs="";
String result="";
strRs=executeSysCMD(cmd);
result = parseCmd(strRs);
return result;
}
private String executeSysCMD(String shellCommand) {
try {
Start(shellCommand);
StringBuffer sb = new StringBuffer();
DataInputStream in = new DataInputStream(p.getInputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
do {
line = reader.readLine();
if (line == null) {
break;
}
else {
sb.append(line);
}
}
while (true);
reader.close();
return sb.toString();
}
catch (Exception e) {
//error
return null;
}
}
java在server端执行
应该获得的是server的MAC才对啊
怎么会是Client的呢
int indexof = str.indexOf("\r");
if(indexof>0)
return str.substring(0,indexof).trim();
return str;
}
不太明白,为什么需要两句return?
不好意思,没看清楚:)
没看到第一个return上面的if吗?
这个实际上是用ORACLE FORM BUILDER开发的WEB程序,为了取得
MAC,所以追加了数字签名等处理.但是,现在不管是B/S的还是WEB程序,都是出现以上情况的.
包括在JBUILDER中都是出现的.
何须cmd执行