9
0
0

获取单个公网ip

2024-09-10
2024-09-10
文章摘要
|

获取单个公网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

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或者给予支持!

获取单个公网ip
/archives/huo-qu-dan-ge-gong-wang-ip
Author
Administrator
Published at
2024-09-10

欢迎来到我的博客!