#!/usr/bin/python3 # -*- coding: utf-8 -*- # 2026/05/14 import os, sys import tkinter as tk from tkinter import ttk APP_NAME = "Local IP Viewer" DEFAULT_WIDTH = 320 DEFAULT_HEIGHT = 40 def run_cmd(command, display=False, capture=True): for cmd in command.split(): for char in [",", "|", "&"]: cmd = cmd.replace(char, "") if cmd.strip() == "rm": print("'{0}' does not allow to be executed.".format(command)) return False if display: print(command) if capture: return os.popen(command).read().strip() else: os.system(command) def local_ip_viewer(): ipa = run_cmd("ip a|grep \"inet \"|tail -n 1") ip = ipa.split()[1].split("/")[0] #print(ip) root = tk.Tk() root.title(APP_NAME) root.geometry("{0}x{1}".format(DEFAULT_WIDTH, DEFAULT_HEIGHT)) root.resizable(False, False) label = ttk.Label(root, text=ip) label.pack(expand=True) root.mainloop() if __name__ == "__main__": local_ip_viewer()