Here is the easy part
import tkinter as tk
import random
import netifaces
class AtoDConverterGUI:
def __init__(self, root):
self.root = root
self.root.title("AtoD Converter")
# AtoD Data Section
self.data_frame = tk.Frame(root, padx=10, pady=10)
self.data_frame.pack(pady=10)
self.data_label = tk.Label(self.data_frame, text="AtoD Data:", font=("Arial", 14))
self.data_label.grid(row=0, column=0, sticky="w")
self.data_value = tk.Label(self.data_frame, text="0.0", font=("Arial", 14), fg="blue")
self.data_value.grid(row=0, column=1, sticky="e")
# Network Info Section
self.network_frame = tk.Frame(root, padx=10, pady=10)
self.network_frame.pack(pady=10)
self.ip_label = tk.Label(self.network_frame, text="Target IP Address (Ethernet):", font=("Arial", 12))
self.ip_label.grid(row=0, column=0, sticky="w")
self.hostname_label = tk.Label(self.network_frame, text="Hostname:", font=("Arial", 12))
self.hostname_label.grid(row=1, column=0, sticky="w")
# Get Ethernet IP and Hostname
ethernet_ip = self.get_ethernet_ip()
hostname = ethernet_ip.get('hostname', "Unknown")
ip_address = ethernet_ip.get('ip', "Unknown")
self.ip_value = tk.Label(self.network_frame, text=ip_address, font=("Arial", 12), fg="green")
self.ip_value.grid(row=0, column=1, sticky="e")
self.hostname_value = tk.Label(self.network_frame, text=hostname, font=("Arial", 12), fg="green")
self.hostname_value.grid(row=1, column=1, sticky="e")
# Start Updating AtoD Data
self.update_data()
def update_data(self):
# Simulate data variation (e.g., random float between 0 and 10)
new_value = round(random.uniform(0.0, 10.0), 2)
self.data_value.config(text=str(new_value))
# Schedule the next update
self.root.after(500, self.update_data)
@staticmethod
def get_ethernet_ip():
import socket
eth_interface = None
# Find a likely Ethernet interface
for iface in netifaces.interfaces():
if iface.startswith("eth") or iface.startswith("en"):
eth_interface = iface
break
if eth_interface:
addrs = netifaces.ifaddresses(eth_interface)
if netifaces.AF_INET in addrs:
ip_info = addrs[netifaces.AF_INET][0]
ip_address = ip_info.get('addr', None)
hostname = socket.gethostname()
return {'ip': ip_address, 'hostname': hostname}
return {'ip': "No Ethernet IP Found", 'hostname': "Unknown"}
# Create the main application window
if __name__ == "__main__":
root = tk.Tk()
app = AtoDConverterGUI(root)
root.mainloop()