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 but get None as scan_data :param hosts: string for hosts as nmap use it 'scanme.nmap.org' or '198
( # NOQA: CFQ002
self,
hosts="127.0.0.1",
ports=None,
arguments="-sV",
callback=None,
sudo=False,
timeout=0,
)
| 791 | return |
| 792 | |
| 793 | def scan( # NOQA: CFQ002 |
| 794 | self, |
| 795 | hosts="127.0.0.1", |
| 796 | ports=None, |
| 797 | arguments="-sV", |
| 798 | callback=None, |
| 799 | sudo=False, |
| 800 | timeout=0, |
| 801 | ): |
| 802 | """ |
| 803 | Scan given hosts in a separate process and return host by host result using callback function |
| 804 | |
| 805 | PortScannerError exception from standard nmap is catched and you won't know about but get None as scan_data |
| 806 | |
| 807 | :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' |
| 808 | :param ports: string for ports as nmap use it '22,53,110,143-4564' |
| 809 | :param arguments: string of arguments for nmap '-sU -sX -sC' |
| 810 | :param callback: callback function which takes (host, scan_data) as arguments |
| 811 | :param sudo: launch nmap with sudo if true |
| 812 | :param timeout: int, if > zero, will terminate scan after seconds, otherwise will wait indefintely |
| 813 | |
| 814 | """ |
| 815 | |
| 816 | if sys.version_info[0] == 2: |
| 817 | assert type(hosts) in ( |
| 818 | str, |
| 819 | ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]" |
| 820 | assert type(ports) in ( |
| 821 | str, |
| 822 | type(None), |
| 823 | ), f"Wrong type for [ports], should be a string [was {type(ports)}]" |
| 824 | assert type(arguments) in ( |
| 825 | str, |
| 826 | ), f"Wrong type for [arguments], should be a string [was {type(arguments)}]" |
| 827 | else: |
| 828 | assert ( |
| 829 | type(hosts) is str |
| 830 | ), f"Wrong type for [hosts], should be a string [was {type(hosts)}]" |
| 831 | assert type(ports) in ( |
| 832 | str, |
| 833 | type(None), |
| 834 | ), f"Wrong type for [ports], should be a string [was {type(ports)}]" |
| 835 | assert ( |
| 836 | type(arguments) is str |
| 837 | ), f"Wrong type for [arguments], should be a string [was {type(arguments)}]" |
| 838 | |
| 839 | assert ( |
| 840 | callable(callback) or callback is None |
| 841 | ), f"The [callback] {str(callback)} should be callable or None." |
| 842 | |
| 843 | for redirecting_output in ["-oX", "-oA"]: |
| 844 | assert ( |
| 845 | redirecting_output not in arguments |
| 846 | ), "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 |
| 847 | |
| 848 | self._process = Process( |
| 849 | target=__scan_progressive__, |
| 850 | args=(self, hosts, ports, arguments, callback, sudo, timeout), |