使用JQuery识别本地PC [英] Identify local PC with JQuery

查看:102
本文介绍了使用JQuery识别本地PC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试识别一台PC来检查登录尝试的次数.

Im trying to identify a PC to check on the amount of login attempts.

目前,我正在使用代码来标识PC的IP地址.

At the moment im using code to identify the IP address of the PC.

它运行良好,但是如果您使用的是动态IP,则您遇到的机器人每隔一两秒钟就会更改其IP,那么它将无法正常工作.

It works well, but if you are using a dynamic IP of you encounter a bot that changes its IP every second or two, it wont work.

这是当前代码

<script type="application/javascript">
    $(document).ready(function() {
        $.getJSON("http://www.telize.com/jsonip?callback=?",
            function(json) {
                myIP = json.ip;
            }
        );
    });
</script>

还有其他一些我可以抓取的唯一地址或代码吗? (例如MAC地址,但我知道这是不允许的.)

Is there some other unique address or code that I can grab? (like MAC address, but I know that is not allowed.)

推荐答案

没有设备或浏览器可以返回唯一ID.这将是违反安全性的一种手段.但这仍然是一个很大的问题,许多应用程序都会创建一个uuid,并将其存储在设备上,以便至少在其服务器上可以被识别.

No device or browser can return a unique Id. It would be a means of security breach. None the less it is a great question and many apps create a uuid that is stored on the device so that it can be identified, if at least on their server.

这就是你的做法

http://jsfiddle.net/dq5oy6w2/1/

var uuid=function(){
var u = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
function(c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
return u;
}


var getDeviceId = function(){
var current = window.localStorage.getItem("_DEVICEID_")
if (current) return current;
var id = uuid();
window.localStorage.setItem("_DEVICEID_",id);   
return id;
}

document.getElementById("deviceid").innerHTML=getDeviceId();

在这里我使用localStorage,它的速度很快,但是用户可以在大多数设备上清除它.如果您想要更强大的功能,请考虑使用indexedDB或WebSql-两者在某些方面都很难清除.

Here i use localStorage, it's fast reliable but the user can clear it on most devices. If you want something more robust, consider indexedDB or WebSql -both are harder in some respects to clear.

由于服务器上有ip,因此可以在服务器调用中传递此id,并可以将IP作为备用,如果将此uuid与IP一起存储在服务器上,则可以补充客户端,如果它松开了uuid.但这可能会限制一个IP上的多个设备.

Since you have the ip on the server you could pass this id in your server call, and have the IP as a fallback, if you store this uuid with the IP, on your server: you could have a means of replenishing the client, if it looses the uuid. But that may restrict multiple devices on one IP.

这篇关于使用JQuery识别本地PC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆