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 provides free IP address services

httpbin.org is a free HTTP request and response service that provides a range of APIs, including the ability to obtain a public IP address.

By accessing httpbin.org/ip, you can get your public IP address. The response it returns is in JSON format, which includes information about your public IP address.

There are several advantages to using httpbin.org's free IP address service:

Free: httpbin.org's IP address service is provided free of charge, allowing you to obtain your public IP address at any time without paying any fees.

Easy to use: Simply send an HTTP GET request to httpbin.org/ip to get your public IP address, without the need for complex configuration or authentication processes.

High reliability: httpbin.org is a stable and reliable service, with its APIs consistently available and providing good response speed.

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', 'Unknown City')
    else:
        return 'Unable to retrieve city information'

if __name__ == '__main__':
    public_ip = get_public_ip()
    print(f'Public IP: {public_ip}')
    city = get_city_from_ip(public_ip)
    print(f'City: {city}')
    while True:
        time.sleep(1)

Graphical version:

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', 'Unknown City')
        else:
            return 'Unable to retrieve city information'
    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'Public IP: {public_ip}')
    city_label.config(text=f'City: {city}')

# Create main window
root = Tk()
root.title("Get Public IP and City")
root.geometry("450x150")

# Create labels
ip_label = Label(root, text="Public IP: Waiting for retrieval...")
city_label = Label(root, text="City: Waiting for retrieval...")
ip_label.pack(pady=10)
city_label.pack(pady=10)

# Create button
style = ttk.Style()
style.configure("TButton", font=("Arial", 12))
get_button = ttk.Button(root, text="Get IP and City", command=update_city, style="TButton")
get_button.pack(pady=10)

# Run main loop
root.mainloop()
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.