1
+ from tkinter import PhotoImage
1
2
import tkinter as tk
2
3
from threading import Thread
3
- from scapy .all import *
4
4
import os
5
5
import psutil
6
- from collections import defaultdict
7
6
from win32api import GetMonitorInfo , MonitorFromPoint
8
7
9
8
KB = float (1024 )
10
9
MB = float (KB ** 2 )
11
10
GB = float (KB ** 3 )
12
11
TB = float (KB ** 4 )
13
- all_macs = {iface .mac for iface in ifaces .values ()}
14
12
15
- WINDOW_SIZE = (240 , 280 )
16
- WINDOW_RESIZEABLE = True
13
+ WINDOW_SIZE = (525 , 30 )
14
+ WINDOW_RESIZEABLE = True
17
15
REFRESH_DELAY = 1500
18
16
19
17
last_upload , last_download , upload_speed , down_speed = 0 , 0 , 0 , 0
18
+
20
19
def size (B ):
21
20
B = float (B )
22
21
if B < KB :
23
- return f"{ B } Bytes"
22
+ return f"{ B :.2f } Bytes"
24
23
elif KB <= B < MB :
25
24
return f"{ B / KB :.2f} KB"
26
25
elif MB <= B < GB :
@@ -29,12 +28,26 @@ def size(B):
29
28
return f"{ B / GB :.2f} GB"
30
29
elif TB <= B :
31
30
return f"{ B / TB :.2f} TB"
31
+ prev_x = 0
32
+ prev_y = 0
33
+
34
+ def start_drag (event ):
35
+ global prev_x , prev_y
36
+ prev_x , prev_y = event .x_root , event .y_root
37
+
38
+ def on_drag (event ):
39
+ global prev_x , prev_y
40
+ x , y = event .x_root - prev_x , event .y_root - prev_y
41
+ window .geometry (f"+{ window .winfo_x () + x } +{ window .winfo_y () + y } " )
42
+ prev_x , prev_y = event .x_root , event .y_root
43
+
32
44
window = tk .Tk ()
33
45
window .title ("Network Bandwidth Monitor" )
34
46
window .attributes ("-topmost" , True )
47
+ window .overrideredirect (True )
35
48
screen_width = window .winfo_screenwidth ()
36
49
screen_height = window .winfo_screenheight ()
37
-
50
+ image = PhotoImage ( file = 'drag.png' )
38
51
monitor_info = GetMonitorInfo (MonitorFromPoint ((0 ,0 )))
39
52
work_area = monitor_info .get ("Work" )[3 ]
40
53
@@ -44,41 +57,22 @@ def size(B):
44
57
window .geometry (f"{ WINDOW_SIZE [0 ]} x{ WINDOW_SIZE [1 ]} +{ window_x } +{ window_y } " )
45
58
window .resizable (width = WINDOW_RESIZEABLE , height = WINDOW_RESIZEABLE )
46
59
47
- label_total_upload_header = tk .Label (text = "Total Upload:" , font = "Quicksand 12 bold" )
48
- label_total_upload_header .pack ()
49
- label_total_upload = tk .Label (text = "Calculating..." , font = "Quicksand 12" )
50
- label_total_upload .pack ()
51
-
52
- label_total_download_header = tk .Label (text = "Total Download:" , font = "Quicksand 12 bold" )
53
- label_total_download_header .pack ()
54
- label_total_download = tk .Label (text = "Calculating..." , font = "Quicksand 12" )
55
- label_total_download .pack ()
56
-
57
- label_total_usage_header = tk .Label (text = "Total Network Usage:" , font = "Quicksand 12 bold" )
58
- label_total_usage_header .pack ()
59
- label_total_usage = tk .Label (text = "Calculating...\n " , font = "Quicksand 12" )
60
- label_total_usage .pack ()
61
-
62
- label_upload_header = tk .Label (text = "Upload Speed:" , font = "Quicksand 12 bold" )
63
- label_upload_header .pack ()
64
- label_upload = tk .Label (text = "Calculating..." , font = "Quicksand 12" )
65
- label_upload .pack ()
66
-
67
- label_download_header = tk .Label (text = "Download Speed:" , font = "Quicksand 12 bold" )
68
- label_download_header .pack ()
69
- label_download = tk .Label (text = "Calculating..." , font = "Quicksand 12" )
70
- label_download .pack ()
71
-
72
- def process_packet (packet ):
73
- pass
74
-
75
- def start_packet_capture ():
76
- while True :
77
- sniff (filter = "tcp or udp and (portrange 1-65535)" , prn = process_packet , count = 1 , store = 0 )
78
-
79
- packet_capture_thread = Thread (target = start_packet_capture )
80
- packet_capture_thread .daemon = True
81
- packet_capture_thread .start ()
60
+ label_usage = tk .Label (text = "Usage:" ,font = "Quicksand 12 bold" )
61
+ label_usage .grid (row = 1 ,column = 1 )
62
+ usagedata = tk .Label (text = "Calculating..." , font = "Quicksand 12" ,fg = "gray" )
63
+ usagedata .grid (row = 1 ,column = 2 )
64
+ uplabel = tk .Label (text = "| ⬆ Speed:" , font = "Quicksand 12 bold" )
65
+ uplabel .grid (row = 1 ,column = 3 )
66
+ updata = tk .Label (text = "Calculating..." , font = "Quicksand 12" , fg = "#32CD30" )
67
+ updata .grid (row = 1 ,column = 4 )
68
+ downlabel = tk .Label (text = "| ⬇ Speed:" , font = "Quicksand 12 bold" )
69
+ downlabel .grid (row = 1 ,column = 5 )
70
+ downdata = tk .Label (text = "Calculating..." , font = "Quicksand 12" , fg = "#FF2511" )
71
+ downdata .grid (row = 1 ,column = 6 )
72
+ dragwin = tk .Label (window , image = image )
73
+ dragwin .grid (row = 1 , column = 0 )
74
+ dragwin .bind ("<ButtonPress-1>" , start_drag )
75
+ dragwin .bind ("<B1-Motion>" , on_drag )
82
76
83
77
def update ():
84
78
global last_upload , last_download , upload_speed , down_speed
@@ -103,18 +97,9 @@ def update():
103
97
last_upload = upload
104
98
last_download = download
105
99
106
- label_total_upload ["text" ] = f"{ size (upload )} "
107
- label_total_download ["text" ] = f"{ size (download )} "
108
- label_total_usage ["text" ] = f"{ size (total )} \n "
109
-
110
- label_upload ["text" ] = size (upload_speed )
111
- label_download ["text" ] = size (down_speed )
112
-
113
- label_total_upload .pack ()
114
- label_total_download .pack ()
115
- label_total_usage .pack ()
116
- label_upload .pack ()
117
- label_download .pack ()
100
+ usagedata ["text" ] = f"{ size (total )} "
101
+ updata ["text" ] = f"{ size (upload_speed )} "
102
+ downdata ["text" ] = f"{ size (down_speed )} "
118
103
119
104
window .after (REFRESH_DELAY , update )
120
105
0 commit comments