JS 获取电脑真实IP 地址

时间:2025-01-22 07:20:51
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>GET IP</title>
</head>
<body>
    <div ></div>
</body>
</html>
<script src="/cityjson?ie=utf-8"></script>
<script type="text/javascript">
	// 下面这行和上面的script一起使用  获取真实IP地址
    (returnCitySN["cip"]+','+returnCitySN["cname"] + "真实IP地址")
	// 下面的一堆 单独使用 获取本地的IP地址
    function findIP(callback) {
        var myPeerConnection =  ||  || ; //compatibility for firefox and chrome
        var pc = new myPeerConnection({iceServers: []}),
            noop = function() {},
            localIPs = {},
            ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
            key;

        function ipIterate(ip) {
            if (!localIPs[ip]) callback(ip);
            localIPs[ip] = true;
        }
        ("");
        ().then(function(sdp) {
            ('\n').forEach(function(line) {
                if (('candidate') < 0) return;
                (ipRegex).forEach(ipIterate);
            });
            (sdp, noop, noop);
        });
         = function(ice) {
            if (!ice || ! || ! || !(ipRegex)) return;
            (ipRegex).forEach(ipIterate);
        };
    }

    findIP(function(ip){
        let dom = ('dom')
         = ip + "你的本地IP地址"
    });
</script>