`
田智伟
  • 浏览: 204223 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

jsp中获取用户的mac地址

阅读更多

通过ip获取用户的mac地址

public String getMyIP() {
		try {
		
			return request.getRemoteAddr();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}
	public String getMACAddress(String ip){
		String str = "";
		String macAddress = "";
		try{
			Process p = Runtime.getRuntime().exec("nbtstat -A " + ip);
			InputStreamReader ir = new InputStreamReader(p.getInputStream());
			LineNumberReader input = new LineNumberReader(ir);
			for (int i = 1; i < 100; i++) {
				str = input.readLine();
				if (str != null) {
					if (str.indexOf("MAC Address") > 1) {
						macAddress = str.substring(str.indexOf("MAC Address") + 14, str.length());
					break;
					}
				}
			}
		} catch (IOException e) {
			e.printStackTrace(System.out);
		}
		return macAddress;
	}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics