jsp如何获取客户端的mac地址

  1. import java.io.IOException; 
  2. import java.io.InputStreamReader; 
  3. import java.io.LineNumberReader; 
  4. public class GetMACAddress { 
  5. public String getMACAddress(String ipAddress) { 
  6. String str = "", strMAC = "", macAddress = ""
  7. try { 
  8. Process pp = Runtime.getRuntime().exec("nbtstat -a " + ipAddress); 
  9. InputStreamReader ir = new InputStreamReader(pp.getInputStream()); 
  10. LineNumberReader input = new LineNumberReader(ir); 
  11. for (int i = 1; i < 100; i++) { 
  12. str = input.readLine(); 
  13. if (str != null) { 
  14. if (str.indexOf("MAC Address") > 1) { 
  15. strMAC = str.substring(str.indexOf("MAC Address") + 14
  16. str.length()); 
  17. break
  18. catch (IOException ex) { 
  19. return "Can't Get MAC Address!"
  20. // 
  21. if (strMAC.length() < 17) { 
  22. return "Error!"
  23. macAddress = strMAC.substring(02) + ":" + strMAC.substring(35
  24. ":" + strMAC.substring(68) + ":" + strMAC.substring(911
  25. ":" + strMAC.substring(1214) + ":" 
  26. + strMAC.substring(1517); 
  27. // 
  28. return macAddress; 
  29. public static void main(String[] args) { 
  30. GetMACAddress getMACAddress = new GetMACAddress(); 
  31. System.out.println(getMACAddress.getMACAddress("59.78.63.38")); //获得该ip地址的mac地址 
  32. public static String procAll(String str) { 
  33. return procStringEnd(procFirstMac(procAddress(str))); 
  34. public static String procAddress(String str) { 
  35. int indexof = str.indexOf("Physical Address"); 
  36. if (indexof > 0) { 
  37. return str.substring(indexof, str.length()); 
  38. return str; 
  39. public static String procFirstMac(String str) { 
  40. int indexof = str.indexOf(":"); 
  41. if (indexof > 0) { 
  42. return str.substring(indexof + 1, str.length()).trim(); 
  43. return str; 
  44. public static String procStringEnd(String str) { 
  45. int indexof = str.indexOf("/r"); 
  46. if (indexof > 0) { 
  47. return str.substring(0, indexof).trim(); 
  48. return str; 

 


只要写一个servlet来调用这个类的getMACAddress(String netip)方法就可以获得客户端的mac地址了,相信你会写jsp应该对servlet也不陌生吧,在jsp中调用servlet通过session传递返回的mac地址,加以判断就可以了

 

原文地址:http://hi.baidu.com/fatenumber/blog/item/583f930930dcc4ca3bc7638d.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值