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

Method scan

pager_lib/nmap/nmap.py:912–951  ·  view source on GitHub ↗

Scan given hosts in a separate process and return host by host result using callback function PortScannerError exception from standard nmap is catched and you won't know about it :param hosts: string for hosts as nmap use it 'scanme.nmap.org' or '198.116.0-255.1-127' or '2

(
        self, hosts="127.0.0.1", ports=None, arguments="-sV", sudo=False, timeout=0
    )

Source from the content-addressed store, hash-verified

910 return
911
912 def scan(
913 self, hosts="127.0.0.1", ports=None, arguments="-sV", sudo=False, timeout=0
914 ):
915 """
916 Scan given hosts in a separate process and return host by host result using callback function
917
918 PortScannerError exception from standard nmap is catched and you won't know about it
919
920 :param hosts: string for hosts as nmap use it 'scanme.nmap.org' or '198.116.0-255.1-127' or '216.163.128.20/20'
921 :param ports: string for ports as nmap use it '22,53,110,143-4564'
922 :param arguments: string of arguments for nmap '-sU -sX -sC'
923 :param callback: callback function which takes (host, scan_data) as arguments
924 :param sudo: launch nmap with sudo if true
925 :param timeout: int, if > zero, will terminate scan after seconds, otherwise will wait indefintely
926
927 """
928
929 assert (
930 type(hosts) is str
931 ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]"
932 assert type(ports) in (
933 str,
934 type(None),
935 ), f"Wrong type for [ports], should be a string [was {type(ports)}]"
936 assert (
937 type(arguments) is str
938 ), f"Wrong type for [arguments], should be a string [was {type(arguments)}]"
939
940 for redirecting_output in ["-oX", "-oA"]:
941 assert (
942 redirecting_output not in arguments
943 ), "Xml output can't be redirected from command line.\nYou can access it after a scan using:\nnmap.nm.get_nmap_last_output()" # NOQA: E501
944
945 for host in self._nm.listscan(hosts):
946 try:
947 scan_data = self._nm.scan(host, ports, arguments, sudo, timeout)
948 except PortScannerError:
949 scan_data = None
950 yield (host, scan_data)
951 return
952
953 def stop(self):
954 pass

Callers

nothing calls this directly

Calls 2

listscanMethod · 0.80
scanMethod · 0.45

Tested by

no test coverage detected