MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / csv

Method csv

pager_lib/nmap/nmap.py:667–731  ·  view source on GitHub ↗

returns CSV output as text Example : host;hostname;hostname_type;protocol;port;name;state;product;extrainfo;reason;version;conf;cpe 127.0.0.1;localhost;PTR;tcp;22;ssh;open;OpenSSH;protocol 2.0;syn-ack;5.9p1 Debian 5ubuntu1;10;cpe 127.0.0.1;localhost;PTR;tcp;

(self)

Source from the content-addressed store, hash-verified

665 return False
666
667 def csv(self):
668 """
669 returns CSV output as text
670
671 Example :
672 host;hostname;hostname_type;protocol;port;name;state;product;extrainfo;reason;version;conf;cpe
673 127.0.0.1;localhost;PTR;tcp;22;ssh;open;OpenSSH;protocol 2.0;syn-ack;5.9p1 Debian 5ubuntu1;10;cpe
674 127.0.0.1;localhost;PTR;tcp;23;telnet;closed;;;conn-refused;;3;
675 127.0.0.1;localhost;PTR;tcp;24;priv-mail;closed;;;conn-refused;;3;
676 """
677 assert "scan" in self._scan_result, "Do a scan before trying to get result !"
678
679 if sys.version_info < (3, 0):
680 fd = io.BytesIO()
681 else:
682 fd = io.StringIO()
683
684 csv_ouput = csv.writer(fd, delimiter=";")
685 csv_header = [
686 "host",
687 "hostname",
688 "hostname_type",
689 "protocol",
690 "port",
691 "name",
692 "state",
693 "product",
694 "extrainfo",
695 "reason",
696 "version",
697 "conf",
698 "cpe",
699 ]
700
701 csv_ouput.writerow(csv_header)
702
703 for host in self.all_hosts():
704 for proto in self[host].all_protocols():
705 if proto not in ["tcp", "udp"]:
706 continue
707 lport = list(self[host][proto].keys())
708 lport.sort()
709 for port in lport:
710 hostname = ""
711 for h in self[host]["hostnames"]:
712 hostname = h["name"]
713 hostname_type = h["type"]
714 csv_row = [
715 host,
716 hostname,
717 hostname_type,
718 proto,
719 port,
720 self[host][proto][port]["name"],
721 self[host][proto][port]["state"],
722 self[host][proto][port]["product"],
723 self[host][proto][port]["extrainfo"],
724 self[host][proto][port]["reason"],

Callers

nothing calls this directly

Calls 4

all_hostsMethod · 0.95
all_protocolsMethod · 0.80
sortMethod · 0.80
keysMethod · 0.45

Tested by

no test coverage detected