侧边栏壁纸
博主头像
Awesome Devin 博主等级

行动起来,活在当下

  • 累计撰写 345 篇文章
  • 累计创建 26 个标签
  • 累计收到 3 条评论

目 录CONTENT

文章目录

获取单个公网ip

Administrator
2024-09-10 / 0 评论 / 0 点赞 / 8 阅读 / 0 字

获取单个公网ip

根据上篇文章,我们获取到了很全的数据

如果我们只需要直观的看到ip地址怎么处理?

于是使用ChatGPT单独写了一个页面如下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Awesome</title>
</head>
<body>
    <p id="ip">Fetching IP address...</p>

    <script>
        // 发送HTTP GET请求
        fetch('https://ip.dev6.site')
            .then(response => {
                if (response.ok) {
                    return response.json();
                } else {
                    throw new Error(`Failed to retrieve data. HTTP Status code: ${response.status}`);
                }
            })
            .then(data => {
                // 提取ip的值
                const ipValue = data.ip;
                if (ipValue) {
                    document.getElementById('ip').textContent = `${ipValue}`;
                } else {
                    document.getElementById('ip').textContent = "IP value not found in the response.";
                }
            })
            .catch(error => {
                document.getElementById('ip').textContent = `Failed to retrieve data. Error: ${error.message}`;
            });
    </script>
</body>
</html>

显示效果

image

0
博主关闭了所有页面的评论