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()
載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。