Daily

AsmBB
登录

通过浏览器获取设备信息的 js 脚本
0

#96 (ツ) admin
创建于 09:08, 浏览:2 次。

(async () => {
  const ua = navigator.userAgent;
  const uaData = navigator.userAgentData;

  // 获取 User-Agent 高熵信息
  let clientHints = {};
  if (uaData?.getHighEntropyValues) {
    try {
      clientHints = await uaData.getHighEntropyValues([
        "architecture",
        "bitness",
        "model",
        "platform",
        "platformVersion",
        "fullVersionList",
        "wow64"
      ]);
    } catch (e) {}
  }

  // GPU 信息
  function getGPU() {
    const canvas = document.createElement("canvas");
    const gl = canvas.getContext("webgl") ||
               canvas.getContext("experimental-webgl");

    if (!gl) return null;

    const ext = gl.getExtension("WEBGL_debug_renderer_info");

    return {
      vendor: ext
        ? gl.getParameter(ext.UNMASKED_VENDOR_WEBGL)
        : gl.getParameter(gl.VENDOR),
      renderer: ext
        ? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL)
        : gl.getParameter(gl.RENDERER),
      version: gl.getParameter(gl.VERSION),
      shadingLanguage: gl.getParameter(
        gl.SHADING_LANGUAGE_VERSION
      ),
      maxTextureSize: gl.getParameter(gl.MAX_TEXTURE_SIZE)
    };
  }

  // 网络信息
  const connection =
    navigator.connection ||
    navigator.mozConnection ||
    navigator.webkitConnection;

  const network = connection ? {
    effectiveType: connection.effectiveType,
    downlink: connection.downlink,
    rtt: connection.rtt,
    saveData: connection.saveData
  } : "浏览器不支持";

  // 电池信息
  let battery = "浏览器不支持";
  if (navigator.getBattery) {
    try {
      const b = await navigator.getBattery();
      battery = {
        charging: b.charging,
        level: `${Math.round(b.level * 100)}%`,
        chargingTime: b.chargingTime,
        dischargingTime: b.dischargingTime
      };
    } catch (e) {}
  }

  // 操作系统推断
  let os = "Unknown";
  if (/Macintosh|Mac OS X/.test(ua)) os = "macOS";
  else if (/Windows/.test(ua)) os = "Windows";
  else if (/Android/.test(ua)) os = "Android";
  else if (/iPhone|iPad|iPod/.test(ua)) os = "iOS";
  else if (/Linux/.test(ua)) os = "Linux";

  // 浏览器推断
  let browser = "Unknown";
  if (/Edg\//.test(ua)) browser = "Microsoft Edge";
  else if (/Chrome\//.test(ua)) browser = "Google Chrome";
  else if (/Firefox\//.test(ua)) browser = "Firefox";
  else if (/Safari\//.test(ua)) browser = "Safari";

  // 屏幕信息
  const screenInfo = {
    width: screen.width,
    height: screen.height,
    availableWidth: screen.availWidth,
    availableHeight: screen.availHeight,
    colorDepth: screen.colorDepth,
    pixelDepth: screen.pixelDepth,
    devicePixelRatio: devicePixelRatio,
    orientation: screen.orientation?.type
  };

  // 时区
  const timezone = Intl.DateTimeFormat()
    .resolvedOptions().timeZone;

  const info = {
    system: {
      os,
      platform: navigator.platform,
      platformVersion: clientHints.platformVersion,
      architecture: clientHints.architecture,
      bitness: clientHints.bitness,
      deviceModel: clientHints.model || "未暴露",
      userAgent: ua
    },

    browser: {
      name: browser,
      userAgent: ua,
      version: clientHints.fullVersionList ||
        "可从 User-Agent 获取"
    },

    hardware: {
      logicalCpuCores: navigator.hardwareConcurrency,
      memoryGB: navigator.deviceMemory || "未暴露",
      gpu: getGPU()
    },

    display: screenInfo,

    network,

    battery,

    environment: {
      language: navigator.language,
      languages: navigator.languages,
      timezone,
      cookiesEnabled: navigator.cookieEnabled,
      online: navigator.onLine,
      touchPoints: navigator.maxTouchPoints
    }
  };

  console.log("========== 设备信息检测结果 ==========");
  console.table({
    操作系统: info.system.os,
    设备型号: info.system.deviceModel,
    CPU架构: info.system.architecture,
    CPU逻辑核心数: info.hardware.logicalCpuCores,
    内存GB: info.hardware.memoryGB,
    GPU: info.hardware.gpu?.renderer,
    屏幕分辨率:
      `${screen.width} × ${screen.height}`,
    浏览器: info.browser.name,
    时区: timezone
  });

  console.log("完整设备信息:");
  console.log(info);

  // 方便复制 JSON
  const json = JSON.stringify(info, null, 2);
  console.log("JSON 格式:\n" + json);

  if (typeof copy === "function") {
    copy(json);
    console.log("设备信息 JSON 已复制到剪贴板");
  }

  return info;
})();

#97 (ツ) admin
创建于 09:09, 浏览:1 次。
(async () => {
  const info = {};

  // 基本信息
  info["User Agent"] = navigator.userAgent;
  info["平台 (platform)"] = navigator.platform;
  info["语言"] = navigator.language;
  info["时区"] = Intl.DateTimeFormat().resolvedOptions().timeZone;
  info["在线状态"] = navigator.onLine;

  // 硬件相关
  info["CPU 逻辑核心数"] = navigator.hardwareConcurrency;
  info["内存 (GB, 近似值, 部分浏览器支持)"] = navigator.deviceMemory ?? "不支持";
  info["触控点数"] = navigator.maxTouchPoints;

  // 屏幕
  info["屏幕分辨率"] = `${screen.width} x ${screen.height}`;
  info["可用屏幕区域"] = `${screen.availWidth} x ${screen.availHeight}`;
  info["设备像素比"] = window.devicePixelRatio;
  info["色深"] = screen.colorDepth;

  // 高精度设备信息 (Chromium 内核浏览器支持: Chrome / Edge / Opera)
  if (navigator.userAgentData) {
    info["是否移动设备"] = navigator.userAgentData.mobile;
    info["品牌信息"] = navigator.userAgentData.brands
      .map(b => `${b.brand} ${b.version}`).join(", ");
    try {
      const h = await navigator.userAgentData.getHighEntropyValues([
        "model", "platform", "platformVersion", "architecture", "bitness", "fullVersionList"
      ]);
      info["设备型号 (多见于安卓)"] = h.model || "未提供";
      info["系统"] = `${h.platform} ${h.platformVersion}`;
      info["CPU 架构"] = `${h.architecture} ${h.bitness}位`;
    } catch (e) {
      info["高精度信息"] = "获取失败: " + e.message;
    }
  }

  // 显卡信息
  try {
    const gl = document.createElement("canvas").getContext("webgl");
    const ext = gl.getExtension("WEBGL_debug_renderer_info");
    if (ext) {
      info["显卡厂商"] = gl.getParameter(ext.UNMASKED_VENDOR_WEBGL);
      info["显卡型号"] = gl.getParameter(ext.UNMASKED_RENDERER_WEBGL);
    }
  } catch (e) {}

  // 网络
  const c = navigator.connection;
  if (c) {
    info["网络类型"] = c.effectiveType;
    info["下行带宽估算 (Mbps)"] = c.downlink;
    info["延迟估算 (ms)"] = c.rtt;
  }

  // 电池 (部分浏览器支持)
  try {
    if (navigator.getBattery) {
      const b = await navigator.getBattery();
      info["电量"] = Math.round(b.level * 100) + "%";
      info["充电中"] = b.charging;
    }
  } catch (e) {}

  console.table(info);
  return info;
})();

通过浏览器获取设备信息的 js 脚本
0

AsmBB v3.0 (check-in: 3df85ed0b218e51a); SQLite v (check-in: 831d0fb2836b71c9);
©2016..2020 John Found; Licensed under EUPL. Powered by Assembly language Created with Fresh IDE