Skip to content

Instantly share code, notes, and snippets.

@THS-on
Last active October 2, 2016 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save THS-on/9b5bc4e4cc88555af350d649def36baf to your computer and use it in GitHub Desktop.
Save THS-on/9b5bc4e4cc88555af350d649def36baf to your computer and use it in GitHub Desktop.
Helper scripts for Epoptes and BYOD
#!/usr/bin/python2
#Connect to an Epoptes server
import Tkinter
import subprocess
import netifaces
class connect_tk(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.getlocalip()
self.initialize()
def getlocalip(self):
interfaces = netifaces.interfaces()
for i in interfaces:
if i == 'lo':
self.localip = "127.0.0.1"
continue
iface = netifaces.ifaddresses(i).get(netifaces.AF_INET)
if iface != None:
for j in iface:
self.localip = j['addr']
#Connect to an Epoptes server
def connect(self, epoptesip):
print(epoptesip)
subprocess.check_call(["/usr/sbin/epoptes-client", str(epoptesip)])
def initialize(self):
self.grid()
self.entryVariable = Tkinter.StringVar()
self.entry = Tkinter.Entry(self,textvariable=self.entryVariable,font=("Noto Sans UI", 30))
self.entry.grid(column=0,row=0,sticky='EW')
self.entry.bind("<Return>", self.OnPressEnter)
self.entryVariable.set(self.localip)
button = Tkinter.Button(self,text=u"Connect!",
command=self.OnButtonClick,font=("Noto Sans UI", 30))
button.grid(column=1,row=0)
self.labelVariable = Tkinter.StringVar()
label = Tkinter.Label(self,textvariable=self.labelVariable,font=("Noto Sans UI", 30))
label.grid(column=0,row=1,columnspan=2,sticky='EW')
self.labelVariable.set(u"Not connected")
self.grid_columnconfigure(0,weight=1)
self.resizable(True,False)
self.update()
self.geometry(self.geometry())
self.entry.focus_set()
self.entry.selection_range(0, Tkinter.END)
def OnButtonClick(self):
self.connect(self.entryVariable.get())
self.labelVariable.set( "Connected to " + self.entryVariable.get() )
self.entry.focus_set()
self.entry.selection_range(0, Tkinter.END)
def OnPressEnter(self,event):
self.connect(self.entryVariable.get())
self.labelVariable.set( "Connected to " + self.entryVariable.get() )
self.entry.focus_set()
self.entry.selection_range(0, Tkinter.END)
if __name__ == "__main__":
app = connect_tk(None)
app.title('Connect to Epoptes')
app.mainloop()
#!/usr/bin/python2
# Network Code from http://stackoverflow.com/questions/11735821/python-get-localhost-ip
import Tkinter
import netifaces
class show_ip_tk(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.getip()
self.initialize()
#Get IP Adress
def getip(self):
interfaces = netifaces.interfaces()
for i in interfaces:
if i == 'lo':
self.ip = " Not connected "
continue
iface = netifaces.ifaddresses(i).get(netifaces.AF_INET)
if iface != None:
for j in iface:
self.ip = j['addr']
def initialize(self):
self.grid()
button = Tkinter.Button(self,text=u"Reload",
command=self.OnButtonClick)
button.grid(column=1,row=0)
self.labelVariable = Tkinter.StringVar()
label = Tkinter.Label(self,textvariable=self.labelVariable,font=("Noto Sans UI", 50))
label.grid(column=0,row=0,sticky='EW')
self.labelVariable.set(self.ip)
self.grid_columnconfigure(0,weight=1)
self.resizable(True,False)
self.update()
self.geometry(self.geometry())
def OnButtonClick(self):
self.getip()
self.labelVariable.set(self.ip)
if __name__ == "__main__":
app = show_ip_tk(None)
app.title('Show IP Adress')
app.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment