Initialize PortScanner module * detects nmap on the system and nmap version * may raise PortScannerError exception if nmap is not found in the path :param nmap_search_path: tupple of string where to search for nmap executable. Chang
(
self,
nmap_search_path=(
"nmap",
"/usr/bin/nmap",
"/usr/local/bin/nmap",
"/sw/bin/nmap",
"/opt/local/bin/nmap",
),
)
| 75 | """ |
| 76 | |
| 77 | def __init__( |
| 78 | self, |
| 79 | nmap_search_path=( |
| 80 | "nmap", |
| 81 | "/usr/bin/nmap", |
| 82 | "/usr/local/bin/nmap", |
| 83 | "/sw/bin/nmap", |
| 84 | "/opt/local/bin/nmap", |
| 85 | ), |
| 86 | ): |
| 87 | """ |
| 88 | Initialize PortScanner module |
| 89 | |
| 90 | * detects nmap on the system and nmap version |
| 91 | * may raise PortScannerError exception if nmap is not found in the path |
| 92 | |
| 93 | :param nmap_search_path: tupple of string where to search for nmap executable. |
| 94 | Change this if you want to use a specific version of nmap. |
| 95 | :returns: nothing |
| 96 | |
| 97 | """ |
| 98 | self._nmap_path = "" # nmap path |
| 99 | self._scan_result = {} |
| 100 | self._nmap_version_number = 0 # nmap version number |
| 101 | self._nmap_subversion_number = 0 # nmap subversion number |
| 102 | self._nmap_last_output = "" # last full ascii nmap output |
| 103 | is_nmap_found = False # true if we have found nmap |
| 104 | |
| 105 | self.__process = None |
| 106 | |
| 107 | # regex used to detect nmap (http or https) |
| 108 | regex = re.compile(r"Nmap version [0-9]*\.[0-9]*[^ ]* \( http(|s)://.* \)") |
| 109 | # launch 'nmap -V', we wait after |
| 110 | # > 'Nmap version 5.0 ( http://nmap.org )' |
| 111 | # This is for Mac OSX. When idle3 is launched from the finder, PATH is not set so nmap was not found |
| 112 | for nmap_path in nmap_search_path: |
| 113 | try: |
| 114 | if ( |
| 115 | sys.platform.startswith("freebsd") |
| 116 | or sys.platform.startswith("linux") |
| 117 | or sys.platform.startswith("darwin") |
| 118 | ): |
| 119 | p = subprocess.Popen( |
| 120 | [nmap_path, "-V"], |
| 121 | bufsize=10000, |
| 122 | stdout=subprocess.PIPE, |
| 123 | close_fds=True, |
| 124 | ) |
| 125 | else: |
| 126 | p = subprocess.Popen( |
| 127 | [nmap_path, "-V"], bufsize=10000, stdout=subprocess.PIPE |
| 128 | ) |
| 129 | |
| 130 | except OSError: |
| 131 | pass |
| 132 | else: |
| 133 | self._nmap_path = nmap_path # save path |
| 134 | break |
no test coverage detected