Code With Python
39.2K subscribers
890 photos
27 videos
22 files
771 links
This channel delivers clear, practical content for developers, covering Python, Django, Data Structures, Algorithms, and DSA – perfect for learning, coding, and mastering key programming skills.
Admin: @HusseinSheikho || @Hussein_Sheikho
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

https://t.iss.one/DataScience4
5👍3