|
@@ -0,0 +1,165 @@
|
|
|
+#! /usr/bin/python
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
+
|
|
|
+"""
|
|
|
+Valid-License-Identifier: GPL-2.0-only
|
|
|
+SPDX-URL: https://spdx.org/licenses/GPL-1.0.html
|
|
|
+
|
|
|
+(c) 2012 micha@librelight.de
|
|
|
+"""
|
|
|
+
|
|
|
+import os
|
|
|
+import time
|
|
|
+import struct
|
|
|
+import sys
|
|
|
+import tkinter as Tkinter
|
|
|
+import _thread as thread
|
|
|
+
|
|
|
+import nodescan
|
|
|
+
|
|
|
+title = "TK-Ping"
|
|
|
+sys.stdout.write("\x1b]2;"+title+"\x07")
|
|
|
+
|
|
|
+font1 = ("Helvetica", 8)
|
|
|
+font2 = ("Helvetica", 12) # 10
|
|
|
+font3 = ("Helvetica", 12) # 16
|
|
|
+font20 = font=("Helvetica", 12) # 22
|
|
|
+font120 = font=("Helvetica", 22) # 22
|
|
|
+
|
|
|
+
|
|
|
+root = Tkinter.Tk()
|
|
|
+#root.geometry("900x700+100+100")
|
|
|
+root.geometry("500x800+100+100")
|
|
|
+root.title( title)
|
|
|
+
|
|
|
+eframe = Tkinter.Frame(root)
|
|
|
+eframe.pack(side="top",expand=0,fill="x")
|
|
|
+eframe1 = Tkinter.Frame(root)
|
|
|
+eframe1.pack(side="top",expand=1,fill="both")
|
|
|
+
|
|
|
+
|
|
|
+#-------------------------------------------- line
|
|
|
+line_frame = Tkinter.Frame(eframe)
|
|
|
+line_frame.pack(side="top",expand=0,fill="x")
|
|
|
+
|
|
|
+
|
|
|
+local_ips = []
|
|
|
+#local_ips.append("2.0.0.255")
|
|
|
+cmd='ip a | grep " inet " | cut -d " " -f 6 | sort -h'
|
|
|
+r=os.popen(cmd)
|
|
|
+print("cmd",cmd)
|
|
|
+txt=r.readlines()
|
|
|
+for ip in txt:
|
|
|
+ ip = ip.strip()
|
|
|
+ print([ip])
|
|
|
+ if ip.startswith("127."):
|
|
|
+ continue
|
|
|
+ if ip.count(".") != 3:
|
|
|
+ continue
|
|
|
+
|
|
|
+ print("-",ip)
|
|
|
+ local_ips.append(ip)
|
|
|
+
|
|
|
+#local_ips.sort()
|
|
|
+
|
|
|
+option_list=local_ips
|
|
|
+p_variable = Tkinter.StringVar(root)
|
|
|
+p_variable.set(option_list[0]) # default value
|
|
|
+e_poll_new = Tkinter.OptionMenu(line_frame, p_variable,*option_list)
|
|
|
+e_poll_new.configure(font=("Helvetica", 13))
|
|
|
+e_poll_new.configure(width=16)
|
|
|
+e_poll_new["bg"] = "#fff"
|
|
|
+#print(dir(e_poll_new))
|
|
|
+e_poll_new.option_add("end","") #', 'option_clear', 'option_get
|
|
|
+e_poll_new.option_add("end","215.0.0.0")
|
|
|
+e_poll_new.pack(side="left")
|
|
|
+#exit()
|
|
|
+
|
|
|
+
|
|
|
+import queue
|
|
|
+q = queue.Queue()
|
|
|
+
|
|
|
+def sort_list():
|
|
|
+ lines = b_scan.get("0.0","end")
|
|
|
+ lines = lines.split("\n")
|
|
|
+ lines = list(set(lines))
|
|
|
+ lines.sort()
|
|
|
+ b_scan.delete("0.0","end")
|
|
|
+ for line in lines:
|
|
|
+ #print("-",[line])
|
|
|
+ if line:
|
|
|
+ b_scan.insert("end",line+"\n")
|
|
|
+
|
|
|
+def cmd(CMD):
|
|
|
+ print("CMD:",CMD)
|
|
|
+ #b_scan.insert("end",CMD+"\n")
|
|
|
+
|
|
|
+ ip = "xxx"
|
|
|
+ try:
|
|
|
+ ip = p_variable.get() # = Tkinter.StringVar(root)
|
|
|
+ ip = ip.split("/")[0]
|
|
|
+ ip = ip.split(".")
|
|
|
+ ip = "{}.{}.{}.{:03}".format(ip[0],ip[1],ip[2],int(ip[3]))
|
|
|
+ except Exception as e:
|
|
|
+ print("err",e)
|
|
|
+
|
|
|
+ r=os.popen(CMD+" 2> /dev/null ")
|
|
|
+ for line in r.readlines():
|
|
|
+ print([line])
|
|
|
+ if " packets transmitted" in line and not "100%" in line:
|
|
|
+ print(CMD,[line])
|
|
|
+ if ip in CMD:
|
|
|
+ b_scan.insert("end",str(CMD).ljust(50," ")+str(" OK <-- me ")+"\n")
|
|
|
+ else:
|
|
|
+ b_scan.insert("end",str(CMD).ljust(50," ")+str(" OK")+"\n")
|
|
|
+
|
|
|
+
|
|
|
+ping_lock=0
|
|
|
+def _ping():
|
|
|
+ global ping_lock
|
|
|
+ if ping_lock:
|
|
|
+ return
|
|
|
+ btn_ping["bg"] = "orange"
|
|
|
+ ping_lock=1
|
|
|
+ b_scan.insert("end","\n")
|
|
|
+ ip = p_variable.get() # = Tkinter.StringVar(root)
|
|
|
+ ip = ".".join(ip.split(".")[:-1])
|
|
|
+ print("ip",ip)
|
|
|
+ for i in range(1,255):
|
|
|
+ CMD="ping -c1 '{}.{:03}' ".format(ip,i)
|
|
|
+ #cmd(CMD)
|
|
|
+ thread.start_new_thread(cmd,(CMD,)) #node_cmd_recive, () )
|
|
|
+ ping_lock=0
|
|
|
+ btn_ping["bg"] = "green"
|
|
|
+ #sort_list()
|
|
|
+
|
|
|
+def ping():
|
|
|
+ thread.start_new_thread(_ping,()) #node_cmd_recive, () )
|
|
|
+
|
|
|
+#-------------------------------------------- line
|
|
|
+
|
|
|
+btn_ping = Tkinter.Button(line_frame,text="start Ping",width=8,command=ping,font=font2)
|
|
|
+btn_ping.pack(side="left",expand=0,fill="y")
|
|
|
+
|
|
|
+#-------------------------------------------- line
|
|
|
+b_scan2 = Tkinter.Button(line_frame,text="sort",width=8,command=sort_list,font=font2)
|
|
|
+b_scan2.pack(side="left",expand=0,fill="y")
|
|
|
+#-------------------------------------------- line
|
|
|
+
|
|
|
+eframe10 = Tkinter.Frame(eframe1)
|
|
|
+eframe10.pack(side="top",expand=1,fill="both")
|
|
|
+
|
|
|
+scroll_bar = Tkinter.Scrollbar(eframe10)
|
|
|
+scroll_bar.pack(side="right", fill="y")
|
|
|
+
|
|
|
+b_scan = Tkinter.Text(eframe10,width=20,font=font2,yscrollcommand = scroll_bar.set)
|
|
|
+b_scan.pack(side="left",expand=1,fill="both")
|
|
|
+
|
|
|
+scroll_bar.config( command = b_scan.yview )
|
|
|
+#-------------------------------------------- line
|
|
|
+
|
|
|
+
|
|
|
+root.mainloop()
|
|
|
+
|
|
|
+
|
|
|
+
|