banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

httpbin免费提供IP地址服务

httpbin.org 是一个免费的 HTTP 请求和响应服务,它提供了一系列的 API,其中包括获取公网 IP 地址的功能。

通过访问 httpbin.org/ip,你可以获取到你的公网 IP 地址。它返回的响应是一个 JSON 格式的数据,其中包含了你的公网 IP 地址信息。

使用 httpbin.org 的免费 IP 地址服务有以下几个优点:

免费:httpbin.org 的 IP 地址服务是免费提供的,你可以随时使用它来获取公网 IP 地址,无需支付任何费用。

简单易用:只需发送一个 HTTP GET 请求到 httpbin.org/ip,就可以获取到你的公网 IP 地址,无需复杂的配置或认证过程。

可靠性高:httpbin.org 是一个稳定可靠的服务,它的 API 一直保持可用性,并且提供了良好的响应速度。

import requests
import time

def get_public_ip():
    response = requests.get('https://httpbin.org/ip')
    ip_info = response.json()
    return ip_info['origin']

def get_city_from_ip(ip):
    url = f'http://ip-api.com/json/{ip}?fields=city'
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        return data.get('city', '未知城市')
    else:
        return '无法获取城市信息'

if __name__ == '__main__':
    public_ip = get_public_ip()
    print(f'公网IP: {public_ip}')
    city = get_city_from_ip(public_ip)
    print(f'城市: {city}')
    while True:
        time.sleep(1)

图形版;

import requests
from tkinter import Tk, Label, Button
from tkinter import ttk

def get_public_ip():
    try:
        response = requests.get('https://httpbin.org/ip')
        ip_info = response.json()
        return ip_info['origin']
    except requests.RequestException as e:
        return str(e)

def get_city_from_ip(ip):
    try:
        url = f'http://ip-api.com/json/{ip}?fields=city'
        response = requests.get(url)
        if response.status_code == 200:
            data = response.json()
            return data.get('city', '未知城市')
        else:
            return '无法获取城市信息'
    except requests.RequestException as e:
        return str(e)

def update_city():
    public_ip = get_public_ip()
    city = get_city_from_ip(public_ip)
    ip_label.config(text=f'公网IP: {public_ip}')
    city_label.config(text=f'城市: {city}')

# 创建主窗口
root = Tk()
root.title("获取公网IP和城市")
root.geometry("450x150")

# 创建标签
ip_label = Label(root, text="公网IP: 正在等待获取中...")
city_label = Label(root, text="城市: 正在等待获取中...")
ip_label.pack(pady=10)
city_label.pack(pady=10)

# 创建按钮
style = ttk.Style()
style.configure("TButton", font=("Arial", 12))
get_button = ttk.Button(root, text="获取IP和城市", command=update_city, style="TButton")
get_button.pack(pady=10)

# 运行主循环
root.mainloop()
加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。