获取你的ip地址和浏览器信息

回忆 (UID: 977) [复制链接]
帖子链接已复制到剪贴板
帖子已经有人评论啦,不支持删除!

674 2

可能有bug,可复制代码通过在线演示


<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>浏览器信息和IP地址</title>
<style>
  body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f4f4f4;
    color: #333;
    padding: 20px;
    text-align: center;
  }
  .container {
    max-width: 800px;
    margin: 0 auto;
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  }
  h1 {
    color: #5c67f2;
    margin-bottom: 20px;
  }
  button {
    background-color: #5c67f2;
    color: white;
    border: none;
    padding: 10px 20px;
    margin: 5px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s ease;
  }
  button:hover {
    background-color: #4a54e1;
  }
  table {
    width: 100%;
    margin-top: 20px;
    border-collapse: collapse;
  }
  th, td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
  }
  th {
    background-color: #f2f2f2;
  }
</style>
</head>
<body>
<div class="container">
  <h1>检查您的浏览器信息和IP地址</h1>

  <button id="getBrowserInfo" class="btn">获取浏览器信息</button>
  <button id="getIPAddress" class="btn">获取IP地址</button>

  <table id="browserInfoTable" style="display:none;">
    <thead>
      <tr>
        <th>分类</th>
        <th>信息</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>浏览器</td>
        <td id="browserName">-</td>
      </tr>
      <tr>
        <td>版本</td>
        <td id="browserVersion">-</td>
      </tr>
      <tr>
        <td>操作系统</td>
        <td id="os">-</td>
      </tr>
      <tr>
        <td>用户代理字符串</td>
        <td id="userAgent">-</td>
      </tr>
    </tbody>
  </table>

  <table id="ipAddressTable" style="display:none;">
    <thead>
      <tr>
        <th>分类</th>
        <th>信息</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>IP地址</td>
        <td id="ip">-</td>
      </tr>
    </tbody>
  </table>
</div>

<script>
document.getElementById('getBrowserInfo').addEventListener('click', function() {
  const userAgent = navigator.userAgent;
  const browserInfo = {
    browserName: userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*([\d\.]+)/i) || [],
    browserVersion: userAgent.match(/version\/([\d\.]+)/i) || [],
    os: userAgent.match(/(macintosh|windows|linux)/i) || [],
    userAgent: userAgent
  };

  document.getElementById('browserName').textContent = browserInfo.browserName[0].toUpperCase() + browserInfo.browserName[1] || '未知';
  document.getElementById('browserVersion').textContent = browserInfo.browserVersion[0].toUpperCase() + browserInfo.browserVersion[1] || '未知';
  document.getElementById('os').textContent = browserInfo.os[0].toUpperCase() || '未知';
  document.getElementById('userAgent').textContent = browserInfo.userAgent;

  document.getElementById('browserInfoTable').style.display = 'table';
});

document.getElementById('getIPAddress').addEventListener('click', function() {
  fetch('https://api.ipify.org?format=json')
    .then(response => response.json())
    .then(data => {
      document.getElementById('ip').textContent = data.ip;
      document.getElementById('ipAddressTable').style.display = 'table';
    })
    .catch(error => {
      document.getElementById('ip').textContent = `获取失败: ${error}`;
      document.getElementById('ipAddressTable').style.display = 'table';
    });
});
</script>
</body>
</html>
这家伙太懒了,什么也没留下。
已有评论 ( 2 )
提示:您必须 登录 才能查看此内容。
创建新帖
自助推广点击空位自助购买TG联系
确认删除
确定要删除这篇帖子吗?删除后将无法恢复。
删除成功
帖子已成功删除,页面将自动刷新。
删除失败
删除帖子时发生错误,请稍后再试。