Jump to content

Python DNS and IP change programm

FreQUENCY

Hello,

This is a snippet of my project.I want to make a programm that changes the IP and the DNS server at the click of a button.I cant make it work,i cant find out if i must use SUBPROCESS or OS.SYSTEM. Ignore the commented lines please. Thank you!

import os
from tkinter import *

class Window(Frame):


    def __init__(self, master=None):
        Frame.__init__(self, master)                 
        self.master = master
        self.init_window()

    #Creation of init_window
    def init_window(self):

        # changing the title of our master widget      
        self.master.title("GUI")

        # allowing the widget to take the full space of the root window
        self.pack(fill=BOTH, expand=1)

        # creating a button instance
        unibutton = Button(self, text="SXOLH",command="uni()")
        spitibutton = Button(self, text="SPITI",command="spiti()")

        # placing the button on my window
        spitibutton.place(x=0, y=0)
        unibutton.place(x=40, y=0)

    def uni():
        #os.system("ipconfig release")
        subprocess.call('netsh interface ip add dns name="Local Area Connection" addr=10.0.0.1'.split())
        #os.system('netsh interface ip add dns name="Local Area Connection" addr=10.0.0.2 index=2')
        print("g")

    def spiti():
        os.system("ipconfig release")
        os.system("netsh interface ip set address lan dhcp")






root = Tk()

#size of the window
root.geometry("100x100")

app = Window(root)
root.mainloop()  

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×