Changing MAC using python code – GUI interface

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


gui = tk.Tk()
gui.title('MAC-Changer')

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.")
    else:
        print("Changing the MAC Address as per the input")
        subprocess.call(["ifconfig", iface, "down"])
        subprocess.call(["ifconfig", iface, "hw", "ether", nmac])
        subprocess.call(["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)
gui.mainloop()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.