<s> from libnmap . process import NmapProcess <EOL> from libnmap . parser import NmapParser , NmapParserException <EOL> def do_scan ( targets , options ) : <EOL> nm = NmapProcess ( targets , options ) <EOL> rc = nm . run ( ) <EOL> if rc != <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" . format ( nm . stderr ) ) <EOL> try : <EOL> parsed = NmapParser . parse ( nm . stdout ) <EOL> except NmapParserException as e : <EOL> print ( "<STR_LIT>" . format ( e . msg ) ) <EOL> return parsed <EOL> def print_scan ( nmap_report ) : <EOL> print ( "<STR_LIT>" . format ( <EOL> nmap_report . _nmaprun [ '<STR_LIT:version>' ] , <EOL> nmap_report . _nmaprun [ '<STR_LIT>' ] ) ) <EOL> for host in nmap_report . hosts : <EOL> if len ( host . hostnames ) : <EOL> tmp_host = host . hostnames . pop ( ) <EOL> else : <EOL> tmp_host = host . address <EOL> print ( "<STR_LIT>" . format ( <EOL> tmp_host , <EOL> host . address ) ) <EOL> print ( "<STR_LIT>" . format ( host . status ) ) <EOL> print ( "<STR_LIT>" ) <EOL> for serv in host . services : <EOL> pserv = "<STR_LIT>" . format ( <EOL> str ( serv . port ) , <EOL> serv . protocol , <EOL> serv . state , <EOL> serv . service ) <EOL> if len ( serv . banner ) : <EOL> pserv += "<STR_LIT>" . format ( serv . banner ) <EOL> print ( pserv ) <EOL> print ( nmap_report . summary ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> report = do_scan ( "<STR_LIT:127.0.0.1>" , "<STR_LIT>" ) <EOL> print_scan ( report ) </s>
