@@ -386,29 +386,29 @@ def __init__(self, portid, protocol='tcp', state=None,
386386 if service_extras is not None :
387387 self ._service_extras = service_extras
388388
389- """
390- Compares two NmapService objects to see if they are the same or
391- if one of them changed.
389+ def __eq__ (self , other ):
390+ """
391+ Compares two NmapService objects to see if they are the same or
392+ if one of them changed.
392393
393- :param other: NmapService
394+ :param other: NmapService
394395
395- :return: boolean
396- """
397- def __eq__ (self , other ):
396+ :return: boolean
397+ """
398398 rval = False
399399 if (self .__class__ == other .__class__ and self .id == other .id ):
400400 rval = (self .changed (other ) == 0 )
401401 return rval
402402
403- """
404- Compares two NmapService objects to see if they are different
405- if one of them changed.
403+ def __ne__ (self , other ):
404+ """
405+ Compares two NmapService objects to see if they are different
406+ if one of them changed.
406407
407- :param other: NmapService
408+ :param other: NmapService
408409
409- :return: boolean
410- """
411- def __ne__ (self , other ):
410+ :return: boolean
411+ """
412412 rval = True
413413 if (self .__class__ == other .__class__ and self .id == other .id ):
414414 rval = (self .changed (other ) > 0 )
@@ -426,70 +426,68 @@ def __hash__(self):
426426 return (hash (self .port ) ^ hash (self .protocol ) ^ hash (self .state ) ^
427427 hash (self .service ) ^ hash (self .banner ))
428428
429- """
430- Checks if a NmapService is different from another.
429+ def changed (self , other ):
430+ """
431+ Checks if a NmapService is different from another.
431432
432- :param other: NmapService
433+ :param other: NmapService
433434
434- :return: boolean
435- """
436- def changed (self , other ):
435+ :return: boolean
436+ """
437437 return len (self .diff (other ).changed ())
438438
439- """
440- Accessor for port.
441-
442- :return: integer or -1
443- """
444439 @property
445440 def port (self ):
446- return self ._portid
441+ """
442+ Accessor for port.
447443
448- """
449- Accessor for protocol
444+ :return: integer or -1
445+ """
446+ return self ._portid
450447
451- :return: string
452- """
453448 @property
454449 def protocol (self ):
455- return self ._protocol
450+ """
451+ Accessor for protocol
456452
457- """
458- Accessor for service's state (open, filtered, closed,...)
453+ :return: string
454+ """
455+ return self ._protocol
459456
460- :return: string
461- """
462457 @property
463458 def state (self ):
464- return self ._state ['state' ] if 'state' in self ._state else None
459+ """
460+ Accessor for service's state (open, filtered, closed,...)
465461
466- """
467- Accessor for service dictionnary.
462+ :return: string
463+ """
464+ return self ._state ['state' ] if 'state' in self ._state else None
468465
469- :return: dict
470- """
471466 @property
472467 def service (self ):
473- return self ._service ['name' ] if 'name' in self ._service else None
468+ """
469+ Accessor for service dictionnary.
474470
475- """
476- Tells if the port was open or not
471+ :return: dict or None
472+ """
473+ return self ._service ['name' ] if 'name' in self ._service else None
477474
478- :return: boolean
479- """
480475 def open (self ):
481- return (True
482- if 'state' in self ._state and self ._state ['state' ] == 'open'
483- else False )
476+ """
477+ Tells if the port was open or not
484478
485- """
486- Accessor for the service's banner. Only available if the nmap option
487- -sV or similar was used.
479+ :return: boolean
480+ """
481+ return 'state' in self . _state and self . _state [ 'state' ] == 'open'
488482
489- :return: string
490- """
491483 @property
492484 def banner (self ):
485+ """
486+ Accessor for the service's banner. Only available
487+ if the nmap option -sV or similar was used.
488+
489+ :return: string
490+ """
493491 notrelevant = ['name' , 'method' , 'conf' ]
494492 b = ''
495493 if 'method' in self ._service and self ._service ['method' ] == "probed" :
@@ -498,14 +496,14 @@ def banner(self):
498496 if k not in notrelevant ])
499497 return b
500498
501- """
502- Gives a python dictionary of the nse scripts results.
503- The dict key is the name (id) of the nse script and
504- the value is the output of the script.
505-
506- :return: dict
507- """
508499 def scripts_results (self ):
500+ """
501+ Gives a python dictionary of the nse scripts results.
502+ The dict key is the name (id) of the nse script and
503+ the value is the output of the script.
504+
505+ :return: dict
506+ """
509507 scripts_dict = None
510508 try :
511509 scripts_dict = dict ([(bdct ['id' ], bdct ['output' ])
@@ -514,44 +512,43 @@ def scripts_results(self):
514512 pass
515513 return scripts_dict
516514
517- """
518- Accessor for the id() of the NmapService. This is used for
519- diff()ing NmapService object via NmapDiff.
520-
521- :return: tuple
522- """
523515 @property
524516 def id (self ):
525- return (self .protocol , self .port )
517+ """
518+ Accessor for the id() of the NmapService. This is used for
519+ diff()ing NmapService object via NmapDiff.
526520
527- """
528- Return a python dict representation of the NmapService object.
529- This is used to diff() NmapService objects via NmapDiff.
521+ :return: tuple
522+ """
523+ return ( self . protocol , self . port )
530524
531- :return: dict
532- """
533525 def get_dict (self ):
526+ """
527+ Return a python dict representation of the NmapService object.
528+ This is used to diff() NmapService objects via NmapDiff.
529+
530+ :return: dict
531+ """
534532 return ({'id' : str (self .id ), 'port' : str (self .port ),
535533 'protocol' : self .protocol , 'banner' : self .banner ,
536534 'service' : self .service , 'state' : self .state })
537535
538- """
539- Calls NmapDiff to check the difference between self and
540- another NmapService object.
541- Will return a NmapDiff object.
542- This objects return python set() of keys describing the elements
543- which have changed, were added, removed or kept unchanged.
544-
545- :return: NmapDiff object
546- """
547536 def diff (self , other ):
537+ """
538+ Calls NmapDiff to check the difference between self and
539+ another NmapService object.
540+ Will return a NmapDiff object.
541+ This objects return python set() of keys describing the elements
542+ which have changed, were added, removed or kept unchanged.
543+
544+ :return: NmapDiff object
545+ """
548546 return NmapDiff (self , other )
549547
550548
551549class NmapReport (object ):
552550 """
553- :todo:
554- - remove get_raw_data makes no sens
551+ :todo: remove get_raw_data makes no sense
555552 """
556553 def __init__ (self , raw_data = None ):
557554 self ._nmaprun = {}
@@ -645,9 +642,9 @@ def __is_consistent(self):
645642 r = False
646643 rd = self .get_raw_data ()
647644 _consistent_keys = ['_nmaprun' , '_scaninfo' , '_hosts' , '_runstats' ]
648- if (set (_consistent_keys ) == set (rd .keys ()) and
649- len ([k for k in rd .keys () if rd [k ] is not None ]) == 4 ):
650- r = True
645+ if (set (_consistent_keys ) == set (rd .keys ()) and
646+ len ([k for k in rd .keys () if rd [k ] is not None ]) == 4 ):
647+ r = True
651648 return r
652649
653650 def get_dict (self ):
0 commit comments