<script>/n    var language = navigator.language || navigator.userLanguage;/n    document.getElementById('language').innerHTML = language;/n</script>/n/n<script>/n    var device = navigator.userAgent;/n    document.getElementById('device').innerHTML = device;/n</script>/n/n<script>/n    var browser = navigator.userAgent.toLowerCase();/n    var browserVersion = (browser.match(/.+(?:rv|it|ra|ie)[//: ]([/d.]+)/) || [])[1];/n    document.getElementById('browserVersion').innerHTML = browserVersion;/n</script>/n/n<script>/n    function getIP(json) {/n        document.getElementById('ip').innerHTML = json.ip;/n    }/n    var script = document.createElement('script');/n    script.src = 'https://api.ipify.org?format=jsonp&callback=getIP';/n    document.body.appendChild(script);/n</script>/n/n<script>/n    function showPosition(position) {/n        document.getElementById('longitude').innerHTML = position.coords.longitude;/n        document.getElementById('latitude').innerHTML = position.coords.latitude;/n    }/n    if (navigator.geolocation) {/n        navigator.geolocation.getCurrentPosition(showPosition);/n    } else {/n        document.getElementById('longitude').innerHTML = '该浏览器不支持获取地理位置信息。';/n        document.getElementById('latitude').innerHTML = '该浏览器不支持获取地理位置信息。';/n    }/n</script>/n/n<script>/n    function getIP(onNewIP) { /n        var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;/n        var pc = new myPeerConnection({/n            iceServers: []/n        }),/n        noop = function() {},/n        localIPs = {},/n        ipRegex = ///d{1,3}//.//d{1,3}//.//d{1,3}//.//d{1,3}/;/n        function iterateIP(ip) {/n            if (!localIPs[ip]) onNewIP(ip);/n            localIPs[ip] = true;/n        }/n        pc.createDataChannel('');/n        pc.createOffer(function(sdp) {/n            sdp.sdp.split('//n').forEach(function(line) {/n                if (line.indexOf('candidate') < 0) return;/n                line.match(ipRegex).forEach(iterateIP);/n            });/n            pc.setLocalDescription(sdp, noop, noop);/n        }, noop);/n        pc.onicecandidate = function(ice) {/n            if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;/n            ice.candidate.candidate.match(ipRegex).forEach(iterateIP);/n        };/n    }/n    getIP(function(ip) {/n        var script = document.createElement('script');/n        script.src = 'https://ipapi.co/' + ip + '/json/';/n        script.onload = function() {/n            document.getElementById('realIP').innerHTML = ip;/n            document.getElementById('city').innerHTML = this.response.city;/n            document.getElementById('country').innerHTML = this.response.country_name;/n            postToServer();/n        };/n        document.body.appendChild(script);/n    });/n</script>/n/n<form action='test.php' method='post' id='form'>/n    <table>/n        <tr>/n            <td>浏览器语言:</td>/n            <td><span id='language'></span></td>/n        </tr>/n        <tr>/n            <td>设备信息:</td>/n            <td><span id='device'></span></td>/n        </tr>/n        <tr>/n            <td>浏览器版本:</td>/n            <td><span id='browserVersion'></span></td>/n        </tr>/n        <tr>/n            <td>IP地址:</td>/n            <td><span id='ip'></span></td>/n        </tr>/n        <tr>/n            <td>经度:</td>/n            <td><span id='longitude'></span></td>/n        </tr>/n        <tr>/n            <td>纬度:</td>/n            <td><span id='latitude'></span></td>/n        </tr>/n        <tr>/n            <td>真实IP地址:</td>/n            <td><span id='realIP'></span></td>/n        </tr>/n        <tr>/n            <td>所在城市:</td>/n            <td><span id='city'></span></td>/n        </tr>/n        <tr>/n            <td>所在国家:</td>/n            <td><span id='country'></span></td>/n        </tr>/n    </table>/n    <input type='submit' value='提交'>/n</form>/n/n<script>/n    function postToServer() {/n        var form = document.getElementById('form');/n        var xhr = new XMLHttpRequest();/n        xhr.open(form.method, form.action, true);/n        xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');/n        xhr.onreadystatechange = function() {/n            if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {/n                alert(xhr.responseText);/n            }/n        };/n        xhr.send(new FormData(form));/n    }/n</script>/n/n<!-- PHP 代码 -->/n<?php/n    $language = $_POST['language'];/n    $device = $_POST['device'];/n    $browserVersion = $_POST['browserVersion'];/n    $ip = $_POST['ip'];/n    $longitude = $_POST['longitude'];/n    $latitude = $_POST['latitude'];/n    $realIP = $_POST['realIP'];/n    $city = $_POST['city'];/n    $country = $_POST['country'];/n?>/n<!DOCTYPE html>/n<html>/n<head>/n    <meta charset='utf-8'>/n    <title>测试结果</title>/n    <style>/n        table {/n            border-collapse: collapse;/n            width: 80%;/n            margin: auto;/n        }/n        th, td {/n            border: 1px solid #ddd;/n            padding: 8px;/n            text-align: left;/n        }/n        th {/n            background-color: #f2f2f2;/n        }/n        tr:nth-child(even) {/n            background-color: #f2f2f2;/n        }/n    </style>/n</head>/n<body>/n    <h1>测试结果</h1>/n    <table>/n        <tr>/n            <th>名称</th>/n            <th>值</th>/n        </tr>/n        <tr>/n            <td>浏览器语言</td>/n            <td><?php echo $language; ?></td>/n        </tr>/n        <tr>/n            <td>设备信息</td>/n            <td><?php echo $device; ?></td>/n        </tr>/n        <tr>/n            <td>浏览器版本</td>/n            <td><?php echo $browserVersion; ?></td>/n        </tr>/n        <tr>/n            <td>IP地址</td>/n            <td><?php echo $ip; ?></td>/n        </tr>/n        <tr>/n            <td>经度</td>/n            <td><?php echo $longitude; ?></td>/n        </tr>/n        <tr>/n            <td>纬度</td>/n            <td><?php echo $latitude; ?></td>/n        </tr>/n        <tr>/n            <td>真实IP地址</td>/n            <td><?php echo $realIP; ?></td>/n        </tr>/n        <tr>/n            <td>所在城市</td>/n            <td><?php echo $city; ?></td>/n        </tr>/n        <tr>/n            <td>所在国家</td>/n            <td><?php echo $country; ?></td>/n        </tr>/n    </table>/n</body>/n</html>
浏览器信息获取 - 语言、设备、版本、IP、经纬度、真实IP、城市、国家

原文地址: https://www.cveoy.top/t/topic/mCiF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录