可以在后台自动获取电脑信息的代码

废话不多说直接上代码 很有用。。。。。。。。。。。

public String login(Model model, HttpServletRequest request, HttpServletResponse response, HttpSession session)
			throws IOException {

	String remoteHost = null;
	String auth = request.getHeader("Authorization");
	String username = null;

	if (auth == null) {
		response.setStatus(response.SC_UNAUTHORIZED);
		response.setHeader("WWW-Authenticate", "NTLM");
		response.flushBuffer();
		return auth;
	}

	if (auth.startsWith("NTLM ")) {
		byte[] msg = null;
		try {
			msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		int off = 0, length, offset;
		if (msg[8] == 1) {
			byte z = 0;
			byte[] msg1 = { (byte) 'N', (byte) 'T', (byte) 'L', (byte) 'M', (byte) 'S', (byte) 'S', (byte) 'P', z,
					(byte) 2, z, z, z, z, z, z, z, (byte) 40, z, z, z, (byte) 1, (byte) 130, z, z, z, (byte) 2,
					(byte) 2, (byte) 2, z, z, z, z, z, z, z, z, z, z, z, z };
			response.setHeader("WWW-Authenticate", "NTLM " + new sun.misc.BASE64Encoder().encodeBuffer(msg1));

			try {
				response.sendError(response.SC_UNAUTHORIZED);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else if (msg[8] == 3) {
			off = 30;

			length = msg[off + 17] * 256 + msg[off + 16];
			offset = msg[off + 19] * 256 + msg[off + 18];
			remoteHost = new String(msg, offset, length);

			length = msg[off + 1] * 256 + msg[off];
			offset = msg[off + 3] * 256 + msg[off + 2];

			length = msg[off + 9] * 256 + msg[off + 8];
			offset = msg[off + 11] * 256 + msg[off + 10];
			username = new String(msg, offset, length);
			username = (username == null || username.equals("")) ? ""
					: username.replace(username.substring(1, 2), "");
			remoteHost = (remoteHost == null || remoteHost.equals("")) ? ""
					: remoteHost.replace(remoteHost.substring(1, 2), "");

			String pagepath = request.getParameter("pagepath");
			pagepath = pagepath == null || pagepath.equals("") ? "" : pagepath;
			System.out.println(username + " : ");

		}
	}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值