Machine Learning & Artificial Intelligence | Data Science Free Courses
64.2K subscribers
557 photos
2 videos
98 files
425 links
Perfect channel to learn Data Analytics, Data Sciene, Machine Learning & Artificial Intelligence

Admin: @coderfun
Download Telegram
Topic: Python – Create IP Address Tracker GUI using Tkinter

---

### What You'll Build

A desktop app that allows the user to:

β€’ Enter an IP address or domain
β€’ Fetch geolocation data (country, city, ISP, etc.)
β€’ Display it in a user-friendly Tkinter GUI

We'll use the requests library and a free API like ip-api.com.

---

### Step-by-Step Code

import tkinter as tk
from tkinter import messagebox
import requests

# Function to fetch IP information
def track_ip():
    ip = entry.get().strip()
    if not ip:
        messagebox.showwarning("Input Error", "Please enter an IP or domain.")
        return

    try:
        url = f"https://ip-api.com/json/{ip}"
        response = requests.get(url)
        data = response.json()

        if data["status"] == "fail":
            messagebox.showerror("Error", data["message"])
            return

        # Show info
        result_text.set(
            f"IP: {data['query']}\n"
            f"Country: {data['country']}\n"
            f"Region: {data['regionName']}\n"
            f"City: {data['city']}\n"
            f"ZIP: {data['zip']}\n"
            f"ISP: {data['isp']}\n"
            f"Timezone: {data['timezone']}\n"
            f"Latitude: {data['lat']}\n"
            f"Longitude: {data['lon']}"
        )

    except Exception as e:
        messagebox.showerror("Error", str(e))

# GUI Setup
app = tk.Tk()
app.title("IP Tracker")
app.geometry("400x400")
app.resizable(False, False)

# Widgets
tk.Label(app, text="Enter IP Address or Domain:", font=("Arial", 12)).pack(pady=10)

entry = tk.Entry(app, width=40, font=("Arial", 12))
entry.pack()

tk.Button(app, text="Track IP", command=track_ip, font=("Arial", 12)).pack(pady=10)

result_text = tk.StringVar()
result_label = tk.Label(app, textvariable=result_text, justify="left", font=("Courier", 10))
result_label.pack(pady=10)

app.mainloop()


---

### Requirements

Install the requests library if not already installed:

pip install requests


---

### Exercise

β€’ Enhance the app to export the result to a .txt or .csv file
β€’ Add a map preview using a web view or link to Google Maps
β€’ Add dark mode toggle for the GUI

---

#Python #Tkinter #IPTracker #Networking #GUI #DesktopApp
❀7