@@ -2,6 +2,7 @@ use color_eyre::eyre::Result;
2
2
use color_eyre:: owo_colors:: OwoColorize ;
3
3
use dns_lookup:: { lookup_addr, lookup_host} ;
4
4
5
+ use ipnetwork:: IpNetwork ;
5
6
use pnet:: {
6
7
datalink:: NetworkInterface ,
7
8
packet:: {
@@ -39,13 +40,13 @@ pub struct IPTraffic {
39
40
pub struct Sniffer {
40
41
active_tab : TabsEnum ,
41
42
action_tx : Option < UnboundedSender < Action > > ,
42
- active_interface : Option < NetworkInterface > ,
43
43
list_state : ListState ,
44
44
scrollbar_state : ScrollbarState ,
45
45
traffic_ips : Vec < IPTraffic > ,
46
46
scrollview_state : ScrollViewState ,
47
47
udp_sum : f64 ,
48
48
tcp_sum : f64 ,
49
+ active_inft_ips : Vec < IpNetwork > ,
49
50
}
50
51
51
52
impl Default for Sniffer {
@@ -59,13 +60,13 @@ impl Sniffer {
59
60
Self {
60
61
active_tab : TabsEnum :: Discovery ,
61
62
action_tx : None ,
62
- active_interface : None ,
63
63
list_state : ListState :: default ( ) . with_selected ( Some ( 0 ) ) ,
64
64
scrollbar_state : ScrollbarState :: new ( 0 ) ,
65
65
traffic_ips : Vec :: new ( ) ,
66
66
scrollview_state : ScrollViewState :: new ( ) ,
67
67
udp_sum : 0.0 ,
68
68
tcp_sum : 0.0 ,
69
+ active_inft_ips : Vec :: new ( ) ,
69
70
}
70
71
}
71
72
@@ -228,7 +229,7 @@ impl Sniffer {
228
229
Rect {
229
230
x : area. x + 2 ,
230
231
y : area. y + 2 ,
231
- width : area. width / 2 ,
232
+ width : area. width ,
232
233
height : 1 ,
233
234
} ,
234
235
) ;
@@ -240,19 +241,79 @@ impl Sniffer {
240
241
f. render_widget (
241
242
total_upload,
242
243
Rect {
243
- x : area. x + ( area . width / 2 ) + 2 ,
244
- y : area. y + 2 ,
245
- width : area. width / 2 ,
244
+ x : area. x + 2 ,
245
+ y : area. y + 3 ,
246
+ width : area. width ,
246
247
height : 1 ,
247
248
} ,
248
249
) ;
249
250
250
- let top_uploader = Line :: from ( vec ! [ "Top uploader:" . into( ) ] ) ;
251
+ let a_intfs = self . active_inft_ips . clone ( ) ;
252
+ let tu = self
253
+ . traffic_ips
254
+ . iter ( )
255
+ . filter ( |item| {
256
+ let t_ip = item. ip . to_string ( ) ;
257
+ for i_ip in a_intfs. clone ( ) {
258
+ if i_ip. ip ( ) . to_string ( ) == t_ip {
259
+ return false ;
260
+ }
261
+ }
262
+ true
263
+ } )
264
+ . max_by_key ( |t| t. upload as u64 ) ;
265
+
266
+ let mut tu_ip = String :: from ( "" ) ;
267
+ let mut tu_name = String :: from ( "" ) ;
268
+ if tu. is_some ( ) {
269
+ tu_ip = tu. unwrap ( ) . ip . to_string ( ) ;
270
+ tu_name = format ! ( " ({})" , tu. unwrap( ) . hostname) ;
271
+ }
272
+ let top_uploader = Line :: from ( vec ! [
273
+ "Top uploader: " . into( ) ,
274
+ tu_ip. blue( ) ,
275
+ tu_name. magenta( ) ,
276
+ ] ) ;
251
277
f. render_widget (
252
278
top_uploader,
253
279
Rect {
254
280
x : area. x + 2 ,
255
- y : area. y + 4 ,
281
+ y : area. y + 5 ,
282
+ width : area. width ,
283
+ height : 1 ,
284
+ } ,
285
+ ) ;
286
+
287
+ let td = self
288
+ . traffic_ips
289
+ . iter ( )
290
+ . filter ( |item| {
291
+ let t_ip = item. ip . to_string ( ) ;
292
+ for i_ip in a_intfs. clone ( ) {
293
+ if i_ip. ip ( ) . to_string ( ) == t_ip {
294
+ return false ;
295
+ }
296
+ }
297
+ true
298
+ } )
299
+ . max_by_key ( |t| t. download as u64 ) ;
300
+
301
+ let mut td_ip = String :: from ( "" ) ;
302
+ let mut td_name = String :: from ( "" ) ;
303
+ if td. is_some ( ) {
304
+ td_ip = td. unwrap ( ) . ip . to_string ( ) ;
305
+ td_name = format ! ( " ({})" , tu. unwrap( ) . hostname) ;
306
+ }
307
+ let top_downloader = Line :: from ( vec ! [
308
+ "Top downloader: " . into( ) ,
309
+ td_ip. blue( ) ,
310
+ td_name. magenta( ) ,
311
+ ] ) ;
312
+ f. render_widget (
313
+ top_downloader,
314
+ Rect {
315
+ x : area. x + 2 ,
316
+ y : area. y + 6 ,
256
317
width : area. width ,
257
318
height : 1 ,
258
319
} ,
@@ -291,7 +352,7 @@ impl Component for Sniffer {
291
352
}
292
353
293
354
if let Action :: ActiveInterface ( ref interface) = action {
294
- self . active_interface = Some ( interface. clone ( ) ) ;
355
+ self . active_inft_ips = interface. ips . clone ( ) ;
295
356
}
296
357
297
358
if let Action :: PacketDump ( time, packet, packet_type) = action {
0 commit comments