@@ -374,80 +374,80 @@ def __split_scans_in_hosts(scans):
374
374
_split_scans_in_hosts [_s ["host" ]] = []
375
375
_split_scans_in_hosts [_s ["host" ]].append (_s )
376
376
return _split_scans_in_hosts
377
-
377
+
378
378
def files_diff (self , _diff_files = None ):
379
- """
380
- Compare the scan results from different files and print the differences.
381
-
382
- Args:
383
- _diff_files (str): Comma-separated list of file paths to compare. If not provided or empty,
384
- the file paths will be fetched from the configuration.
385
-
386
- Returns:
387
- None
388
- """
389
- if _diff_files is not None and _diff_files != "" :
390
- _files = _diff_files .split ("," )
379
+ """
380
+ Compare the scan results from different files and print the differences.
381
+
382
+ Args:
383
+ _diff_files (str): Comma-separated list of file paths to compare. If not provided or empty,
384
+ the file paths will be fetched from the configuration.
385
+
386
+ Returns:
387
+ None
388
+ """
389
+ if _diff_files is not None and _diff_files != "" :
390
+ _files = _diff_files .split ("," )
391
+ else :
392
+ _files = self ._config .diff_files .split ("," )
393
+ _imported_scans = []
394
+ _importer = None
395
+ if _files is None or len (_files ) < 2 :
396
+ raise DScanInputValidationException ("At least two files must be provided to compare" )
397
+ for _f in _files :
398
+ if _importer is None :
399
+ _importer = Importer (_f , logger = self .logger )
400
+ _r = _importer .load_results_from_file ()
391
401
else :
392
- _files = self ._config .diff_files .split ("," )
393
- _imported_scans = []
394
- _importer = None
395
- if _files is None or len (_files ) < 2 :
396
- raise DScanInputValidationException ("At least two files must be provided to compare" )
397
- for _f in _files :
398
- if _importer is None :
399
- _importer = Importer (_f , logger = self .logger )
400
- _r = _importer .load_results_from_file ()
401
- else :
402
- _importer .filename = _f
403
- _r = _importer .load_results_from_file ()
404
-
405
- _host = _r ._nmaprun ["args" ].split (" " )[- 1 ]
406
- _parsed = Parser .extract_port_scan_dict_results (_r )
407
- if "/" in _host :
408
- raise DScanInputValidationException ("Subnet is not supported for this operation" )
409
- if len (_parsed ) > 1 :
410
- raise DScanInputValidationException ("Only one host per file is supported for this operation" )
411
-
412
- _imported_scans .append (
413
- {
414
- "created_at" : datetime .fromtimestamp (int (
415
- _r ._runstats ["finished" ]["time" ])).strftime (
416
- APP_DATE_FORMAT ) if "finished" in _r ._runstats else None ,
417
- "results" : _parsed [0 ],
418
- "arguments" : _r ._nmaprun ["args" ]
419
- }
420
- )
402
+ _importer .filename = _f
403
+ _r = _importer .load_results_from_file ()
404
+
405
+ _host = _r ._nmaprun ["args" ].split (" " )[- 1 ]
406
+ _parsed = Parser .extract_port_scan_dict_results (_r )
407
+ if "/" in _host :
408
+ raise DScanInputValidationException ("Subnet is not supported for this operation" )
409
+ if len (_parsed ) > 1 :
410
+ raise DScanInputValidationException ("Only one host per file is supported for this operation" )
411
+
412
+ _imported_scans .append (
413
+ {
414
+ "created_at" : datetime .fromtimestamp (int (
415
+ _r ._runstats ["finished" ]["time" ])).strftime (
416
+ APP_DATE_FORMAT ) if "finished" in _r ._runstats else None ,
417
+ "results" : _parsed [0 ],
418
+ "arguments" : _r ._nmaprun ["args" ]
419
+ }
420
+ )
421
421
422
- _final_diffs = []
423
- for i , _ in enumerate (_imported_scans , 1 ):
424
- if i == len (_imported_scans ):
425
- break
426
- __diffs = self ._diffs_between_dicts (
427
- self ._results_to_port_dict (_imported_scans [i - 1 ]["results" ]),
428
- self ._results_to_port_dict (_imported_scans [i ]["results" ]))
429
- _final_diffs .append ({
430
- "ids" : [0 ,0 ],
431
- "uuids" : ["" ,"" ],
432
- "generic" : [
433
- {
434
- "host" : _imported_scans [i - 1 ]["results" ]["host" ],
435
- "arguments" : _imported_scans [i - 1 ]["arguments" ],
436
- "profile_name" : ""
437
- },
438
- {
439
- "host" : _imported_scans [i ]["results" ]["host" ],
440
- "arguments" : _imported_scans [i ]["arguments" ],
441
- "profile_name" : ""
442
- }
443
- ],
444
- "dates" : [
445
- _imported_scans [i - 1 ]["created_at" ],
446
- _imported_scans [i ]["created_at" ]],
447
- "diffs" : __diffs ,
448
- "result_hashes" : ["" ,"" ]
449
- })
450
- return _final_diffs
422
+ _final_diffs = []
423
+ for i , _ in enumerate (_imported_scans , 1 ):
424
+ if i == len (_imported_scans ):
425
+ break
426
+ __diffs = self ._diffs_between_dicts (
427
+ self ._results_to_port_dict (_imported_scans [i - 1 ]["results" ]),
428
+ self ._results_to_port_dict (_imported_scans [i ]["results" ]))
429
+ _final_diffs .append ({
430
+ "ids" : [0 , 0 ],
431
+ "uuids" : ["" , "" ],
432
+ "generic" : [
433
+ {
434
+ "host" : _imported_scans [i - 1 ]["results" ]["host" ],
435
+ "arguments" : _imported_scans [i - 1 ]["arguments" ],
436
+ "profile_name" : ""
437
+ },
438
+ {
439
+ "host" : _imported_scans [i ]["results" ]["host" ],
440
+ "arguments" : _imported_scans [i ]["arguments" ],
441
+ "profile_name" : ""
442
+ }
443
+ ],
444
+ "dates" : [
445
+ _imported_scans [i - 1 ]["created_at" ],
446
+ _imported_scans [i ]["created_at" ]],
447
+ "diffs" : __diffs ,
448
+ "result_hashes" : ["" , "" ]
449
+ })
450
+ return _final_diffs
451
451
452
452
def _list_scans_with_diffs (self , scans ):
453
453
"""
@@ -844,7 +844,7 @@ def import_file(self):
844
844
@import_file .setter
845
845
def import_file (self , value ):
846
846
self ._config .import_file = value
847
-
847
+
848
848
@property
849
849
def diff_files (self ):
850
850
return self ._config .diff_files
0 commit comments