1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| import time
import sys
import Tkinter as tk
from socket import *
IP = "0.0.0.0"
mode = "Unknow"
def find_tibbo(var):
s = socket(AF_INET, SOCK_DGRAM) #UDP with DGRAM
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
s.sendto('X', ('<broadcast>', 65535))
data , addr = s.recvfrom(1024)
print "RECU: ", data, " depuis:",addr #pour debug
IP = addr[0] # just IP, no port
s.close()
var.set(IP)
def auto_man(var2):
print var2
s = socket(AF_INET, SOCK_STREAM) #TCP with STREAM
s.connect((var2,10001))
time.sleep(.1)
s.send("MODE?\n")
time.sleep(.1)
mode = s.recv(1024)
s.close()
var2.set(mode)
if __name__ == '__main__':
app = tk.Tk()
app.geometry('400x400+800+300')
app.title('subrack controler')
ip_variable = tk.StringVar(value=IP)
mode_variable = tk.StringVar(value=mode)
tk.Label(text='Search for IP address').place(x=18,y=15)
tk.Button(text = 'Go',command= lambda var=ip_variable: find_tibbo(var),fg = "blue").place(x=200,y=10)
tk.Label(textvariable=ip_variable).place(x=250,y=15)
tk.Label(text='Mode AUTO or MANUAL ?').place(x=18,y=45)
tk.Button(text = 'Go',command= lambda var1=mode_variable: auto_man(ip_variable),fg = "blue").place(x=200,y=40)
tk.Label(textvariable=mode_variable).place(x=250,y=45)
tk.mainloop() |
Partager