Changing MAC using python code – GUI interface

import sys
import subprocess
import tkinter as tk
from tkinter import tsk

gui = tk.Tk()

interface_name = ttk.Label(gui, text="Enter the interface name: ")
interface_name.grid(row=0, column=0, sticky=tk.W)

intface_name = tk.StringVar()
interface_name_entry = ttk.Entry(gui, width = 20, textvariable=intface_name)
interface_name_entry.grid(row=0, column=1)

mac = ttk.Label(gui, text="Enter new MAC address: ")
mac.grid(row=1, column=0, sticky=tk.W)

mac = tk.StringVar()
mac_addr = ttk.Entry(gui, width=20, textvariable=mac)
mac_addr.grid(row=1, column=1)

def changemac():
    iface = intface_name.get()
    nmac = mac.get()
    if not iface:
        sys.exit("Invalid input.")
    elif not nmac:
        sys.exit("Invalid input.")
        print("Changing the MAC Address as per the input")["ifconfig", iface, "down"])["ifconfig", iface, "hw", "ether", nmac])["ifconfig", iface, "up"])
        sys.exit("MAC Address successfully changed to: ")

mac_button = ttk.Button(gui, text="Change MAC", command=changemac)
mac_button.grid(row=4, column=1)

Leave a Reply