好像只能得到客户端IP吧,或者你在客户端也写个同样的getMacOnWindow(),然后自动发来不就得了.不要告诉我你要用在JSP上.
解决方案 »
- getHibernateTemplate().update()数据更新不到数据库,也输不出Sql执行语句,但前台有显示修改结果?
- Java调用远程bat文件的问题
- 关于利用jdbc连接MySQL数据库的一个疑问
- 一个集合过滤问题
- struts+spring+hibernate的问题
- 怎样用 java 代码读取、分析数据库日志
- JBOSS WEB 控制台左边树显示问题,急请支援!
- Access denied for user 'root'@'localhost' (using password: YES)
- 急关于Ping的问题
- JSP和tomcat中计数器的例子counter.jsp counter.java,counter.txta位置?
- 大侠们请进!!!
- java文件在KDE里为什么一定要填入某个工程才可以编译
方法一:调用Windows的DOS命令,从输出结果中读取MAC地址:public static String getMACAddress() {String address = "";
String os = System.getProperty("os.name");
if ( os != null && os.startsWith("Windows")) {
try {
String command = "cmd.exe /c ipconfig /all";
Process p = Runtime.getRuntime().exec(command);
BufferedReader br =
new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf("Physical Address") > 0) {
int index = line.indexOf(":");
index += 2;
address = line.substring(index);
break;
}
}
br.close();
return address.trim();
}
catch (IOException e) { }
}
return address;
}We can replace the "ipconfig" to "ping x.x.x.x" and "arp -a"...We can get the mac list...haha!!
缺点:只能取得服务器端MAC地址.如果要取得客户端的MAC地址,需用Applet.只针对MS-WIN系统. 方法二:可以用JS或vbscript来调用WMI接口来获取Client端的MAC地址.
http协议可以吗?
写个applet下载到客户端(需要数字签名)执行。
除非你在客户端得到放到request里。
代码如下:
<SCRIPT LANGUAGE="JavaScript">
function getMacAddress(f)
{
try
{
var address = new Array();
var i = 0;
var wsh = new ActiveXObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");
wsh.Run("cmd /C ipconfig /all > c:\\temp.txt",0);
//alert("1")
var file = fso.OpenTextFile("c:\\temp.txt",1);
//alert("2")
var currentLine;
var colon;
while(file.AtEndOfStream!=true)
{
currentLine = file.ReadLine();
if(currentLine.indexOf("Physical Address") >= 0)
{
colon = currentLine.indexOf(":");
address[i] = currentLine.substr(colon + 1);
//alert(address[i]);
f.macname.value = address[i];
i++;
}
}
file.Close()
f = fso.GetFile("c:\\temp.txt");
f.Delete();
}
catch(e)
{
alert("请您将IE安全级别降至最低,然后刷新页面!");
}
}
<SCRIPT>
import java.io.InputStreamReader;
import java.io.*;
class GetMac
{
private static String getMacOnWindow() {
String s = "";
try {
String s1 = "ipconfig /all";
Process process = Runtime.getRuntime().exec(s1);
BufferedReader bufferedreader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String nextLine;
for (String line = bufferedreader.readLine(); line != null; line = nextLine) {
nextLine = bufferedreader.readLine();
if (line.indexOf("Physical Address") <= 0) {
continue;
}
int i = line.indexOf("Physical Address") + 36;
s = line.substring(i);
break;
} bufferedreader.close();
process.waitFor();
} catch (Exception exception) {
s = "";
}
return s.trim();
}
}
public class GetMacOnWindow
{
public static void main(String[] args)
{
System.out.println(GetMac.getMacOnWindow());
}
}
(以上资料来自我参于的一个贴子,仅供学习交流)