lopes / netbox-scanner

A scanner util for NetBox
MIT License
165 stars 40 forks source link

install issues #14

Closed squigley closed 4 years ago

squigley commented 4 years ago

I just tried to install this on CentOS 7.5, and am having some issues:

# pip3 install netbox-scanner WARNING: Running pip install with root privileges is generally not a good idea. Try pip3 install --user instead. Collecting netbox-scanner Downloading https://files.pythonhosted.org/packages/68/d5/e36874a35694a08bcd14f1b2c10b4ce8e274eb04d470d5a23f4e0782ae4c/netbox-scanner-0.7.2.tar.gz Installing collected packages: netbox-scanner Running setup.py install for netbox-scanner ... done Successfully installed netbox-scanner-0.7.2 [root@simon-test ~]# python nbscanner python: can't open file 'nbscanner': [Errno 2] No such file or directory [root@simon-test ~]# find / -name nbscanner [root@simon-test ~]# find / -name netbox-scanner /usr/local/lib/python3.6/site-packages/netbox-scanner [root@simon-test ~]# cd /usr/local/lib/python3.6/site-packages/netbox-scanner [root@simon-test netbox-scanner]# ls -al total 28 drwxr-xr-x. 3 root root 78 Jan 6 15:41 . drwxr-xr-x. 127 root root 8192 Jan 6 15:41 .. -rw-r--r--. 1 root root 1053 Oct 29 2018 dac.py -rw-r--r--. 1 root root 0 Oct 29 2018 __init.py -rw-r--r--. 1 root root 9271 Oct 29 2018 nbscanner.py drwxr-xr-x. 2 root root 95 Jan 6 15:41 \pycache__ [root@simon-test netbox-scanner]# python ./nbscanner.py File "./nbscanner.py", line 195 parsing = self.parser([f'{h[0]}/32' for h in hosts]) ^ SyntaxError: invalid syntax

OK, maybe something wrong with the pip version, let's try manually installing..

# wget https://github.com/forkd/netbox-scanner/archive/master.zip --2020-01-06 15:50:30-- https://github.com/forkd/netbox-scanner/archive/master.zip Resolving github.com (github.com)... 192.30.253.113 Connecting to github.com (github.com)|192.30.253.113|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://codeload.github.com/forkd/netbox-scanner/zip/master [following] --2020-01-06 15:50:30-- https://codeload.github.com/forkd/netbox-scanner/zip/master Resolving codeload.github.com (codeload.github.com)... 192.30.253.121 Connecting to codeload.github.com (codeload.github.com)|192.30.253.121|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/zip] Saving to: ‘master.zip’

[ <=>                                                                                                                            ] 9,054       --.-K/s   in 0.02s   

2020-01-06 15:50:30 (398 KB/s) - ‘master.zip’ saved [9054]

[root@simon-test ~]# unzip netbox-scanner-master.zip -d netbox-scanner unzip: cannot find or open netbox-scanner-master.zip, netbox-scanner-master.zip.zip or netbox-scanner-master.zip.ZIP. [root@simon-test ~]# unzip master.zip -d netbox-scanner Archive: master.zip 02d573d4fa0b85f20ea24b706feb169c181bfe09 creating: netbox-scanner/netbox-scanner-master/ inflating: netbox-scanner/netbox-scanner-master/.gitignore
inflating: netbox-scanner/netbox-scanner-master/LICENSE
inflating: netbox-scanner/netbox-scanner-master/README.md
creating: netbox-scanner/netbox-scanner-master/netbox-scanner/ extracting: netbox-scanner/netbox-scanner-master/netbox-scanner/init.py
inflating: netbox-scanner/netbox-scanner-master/netbox-scanner/dac.py
inflating: netbox-scanner/netbox-scanner-master/netbox-scanner/nbscanner
inflating: netbox-scanner/netbox-scanner-master/netbox-scanner/nbscanner.py
inflating: netbox-scanner/netbox-scanner-master/requirements.txt
inflating: netbox-scanner/netbox-scanner-master/setup.py
[root@simon-test ~]# cd netbox-scanner [root@simon-test netbox-scanner]# pip install -r requirements.txt WARNING: Running pip install with root privileges is generally not a good idea. Try pip install --user instead. Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt' [root@simon-test netbox-scanner]# cd netbox-scanner-master [root@simon-test netbox-scanner-master]# pip install -r requirements.txt WARNING: Running pip install with root privileges is generally not a good idea. Try pip install --user instead. Collecting asn1crypto==0.24.0 (from -r requirements.txt (line 1)) Using cached https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl Collecting bcrypt==3.1.6 (from -r requirements.txt (line 2)) Downloading https://files.pythonhosted.org/packages/d0/79/79a4d167a31cc206117d9b396926615fa9c1fdbd52017bcced80937ac501/bcrypt-3.1.6-cp34-abi3-manylinux1_x86_64.whl (55kB) 100% |████████████████████████████████| 61kB 2.9MB/s Collecting certifi==2019.3.9 (from -r requirements.txt (line 3)) Downloading https://files.pythonhosted.org/packages/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd731e598828d380aa/certifi-2019.3.9-py2.py3-none-any.whl (158kB) 100% |████████████████████████████████| 163kB 3.6MB/s Collecting cffi==1.12.2 (from -r requirements.txt (line 4)) Downloading https://files.pythonhosted.org/packages/20/f7/87b62a8895bf7c93e907b05b97bc4459c81a38a61151f03a6eae13d863aa/cffi-1.12.2-cp36-cp36m-manylinux1_x86_64.whl (428kB) 100% |████████████████████████████████| 430kB 2.3MB/s Requirement already satisfied: chardet==3.0.4 in /usr/lib/python3.6/site-packages (from -r requirements.txt (line 5)) Collecting cpe==1.2.1 (from -r requirements.txt (line 6)) Downloading https://files.pythonhosted.org/packages/cd/8a/1dc2644a1fe6049cff29accd1d5830ef2b51b8c71b95b187a59f884777c7/cpe-1.2.1.tar.gz (2.2MB) 100% |████████████████████████████████| 2.2MB 635kB/s Collecting cryptography==2.6.1 (from -r requirements.txt (line 7)) Downloading https://files.pythonhosted.org/packages/5b/12/b0409a94dad366d98a8eee2a77678c7a73aafd8c0e4b835abea634ea3896/cryptography-2.6.1-cp34-abi3-manylinux1_x86_64.whl (2.3MB) 100% |████████████████████████████████| 2.3MB 592kB/s Collecting idna==2.8 (from -r requirements.txt (line 8)) Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB) 100% |████████████████████████████████| 61kB 2.9MB/s Collecting paramiko==2.4.2 (from -r requirements.txt (line 9)) Downloading https://files.pythonhosted.org/packages/cf/ae/94e70d49044ccc234bfdba20114fa947d7ba6eb68a2e452d89b920e62227/paramiko-2.4.2-py2.py3-none-any.whl (193kB) 100% |████████████████████████████████| 194kB 4.2MB/s Collecting pyasn1==0.4.5 (from -r requirements.txt (line 10)) Downloading https://files.pythonhosted.org/packages/7b/7c/c9386b82a25115cccf1903441bba3cbadcfae7b678a20167347fa8ded34c/pyasn1-0.4.5-py2.py3-none-any.whl (73kB) 100% |████████████████████████████████| 81kB 8.4MB/s Requirement already satisfied: pycparser==2.19 in /usr/local/lib/python3.6/site-packages (from -r requirements.txt (line 11)) Requirement already satisfied: PyNaCl==1.3.0 in /usr/local/lib64/python3.6/site-packages (from -r requirements.txt (line 12)) Collecting pynetbox==4.0.6 (from -r requirements.txt (line 13)) Downloading https://files.pythonhosted.org/packages/08/72/261842773f7f6a66379473eb76dd651117dcfaed0c1c15f4ee4e14b3d5f3/pynetbox-4.0.6.tar.gz (44kB) 100% |████████████████████████████████| 51kB 9.8MB/s Collecting python-nmap==0.6.1 (from -r requirements.txt (line 14)) Downloading https://files.pythonhosted.org/packages/dc/f2/9e1a2953d4d824e183ac033e3d223055e40e695fa6db2cb3e94a864eaa84/python-nmap-0.6.1.tar.gz (41kB) 100% |████████████████████████████████| 51kB 8.8MB/s Collecting requests==2.21.0 (from -r requirements.txt (line 15)) Downloading https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl (57kB) 100% |████████████████████████████████| 61kB 8.5MB/s Collecting six==1.12.0 (from -r requirements.txt (line 16)) Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl Requirement already satisfied: urllib3==1.24.1 in /usr/lib/python3.6/site-packages (from -r requirements.txt (line 17)) Installing collected packages: asn1crypto, cffi, six, bcrypt, certifi, cpe, cryptography, idna, pyasn1, paramiko, requests, pynetbox, python-nmap Found existing installation: cffi 1.13.2 Uninstalling cffi-1.13.2: Successfully uninstalled cffi-1.13.2 Found existing installation: six 1.13.0 Uninstalling six-1.13.0: Successfully uninstalled six-1.13.0 Found existing installation: bcrypt 3.1.7 Uninstalling bcrypt-3.1.7: Successfully uninstalled bcrypt-3.1.7 Running setup.py install for cpe ... done Found existing installation: cryptography 2.8 Uninstalling cryptography-2.8: Successfully uninstalled cryptography-2.8 Found existing installation: pyasn1 0.4.8 Uninstalling pyasn1-0.4.8: Successfully uninstalled pyasn1-0.4.8 Found existing installation: paramiko 2.6.0 Uninstalling paramiko-2.6.0: Successfully uninstalled paramiko-2.6.0 Running setup.py install for pynetbox ... done Running setup.py install for python-nmap ... done Successfully installed asn1crypto-0.24.0 bcrypt-3.1.6 certifi-2019.3.9 cffi-1.12.2 cpe-1.2.1 cryptography-2.6.1 idna-2.8 paramiko-2.4.2 pyasn1-0.4.5 pynetbox-4.0.6 python-nmap-0.6.1 requests-2.21.0 six-1.12.0 [root@simon-test netbox-scanner-master]# ls LICENSE netbox-scanner README.md requirements.txt setup.py [root@simon-test netbox-scanner-master]# ls -al total 20 drwxr-xr-x. 3 root root 118 May 14 2019 . drwxr-xr-x. 3 root root 35 Jan 6 15:50 .. -rw-r--r--. 1 root root 1203 May 14 2019 .gitignore -rw-r--r--. 1 root root 1068 May 14 2019 LICENSE drwxr-xr-x. 2 root root 76 May 14 2019 netbox-scanner -rw-r--r--. 1 root root 2815 May 14 2019 README.md -rw-r--r--. 1 root root 277 May 14 2019 requirements.txt -rw-r--r--. 1 root root 657 May 14 2019 setup.py [root@simon-test netbox-scanner-master]# cd netbox-scanner/ [root@simon-test netbox-scanner]# ls dac.py init.py nbscanner nbscanner.py [root@simon-test netbox-scanner]# [root@simon-test netbox-scanner]# cd .. [root@simon-test netbox-scanner-master]# python netbox-scanner/nbscanner Traceback (most recent call last): File "netbox-scanner/nbscanner", line 5, in from configparser import ConfigParser ImportError: No module named configparser [root@simon-test netbox-scanner-master]# ls LICENSE netbox-scanner README.md requirements.txt setup.py [root@simon-test netbox-scanner-master]# python ./setup.py File "./setup.py", line 11 SyntaxError: Non-ASCII character '\xc3' in file ./setup.py on line 11, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

So I'm lost at this point. I don't know how to configure or run this.

squigley commented 4 years ago

Ah, the issue with the setup script is the accented e character in your name, I removed that and the setup runs, but doesn't help.

# python ./setup.py SyntaxError: Non-ASCII character '\xc3' in file ./setup.py on line 11, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details [root@simon-test netbox-scanner-master]# vi setup.py [root@simon-test netbox-scanner-master]# python ./setup.py usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: setup.py --help [cmd1 cmd2 ...] or: setup.py --help-commands or: setup.py cmd --help

error: no commands supplied

mjforrester commented 4 years ago

I was receiving the same error you initially created this issue to resolve. I was able to resolve it myself by editing line 200 of my previously unedited, freshly unzipped nbscanner.py script file. In your case, based on your first posting, you will need to edit your script's line 195 instead. I am unsure why our nbscanner.py scripts are different. To resolve, remove the "f" from the line.

So, the offensive line changes from: parsing = self.parser([f'{h[0]}/32' for h in hosts])

to this instead: parsing = self.parser(['{h[0]}/32' for h in ``hosts])

Once the file is edited, you should be able to run python3 nbscanner or python nbscanner. This should run successfully now and output this success message, with an install path unique to your system:

Config file was created at /home/netbox/.netbox-scanner.conf
Fill all fields before run the script again.

The installation instructions for both this utility and even for the Netbox web app leave so very much to be desired. I had to fight my way through both installations on a pretty standard Ubuntu install that meets all requirements. Regardless of that critique, I am still hopeful that both this utility and Netbox can serve my needs for an IPAM system that self discovers my network. I wish NetDisco had an IPAM component

Best wishes on your endeavors into using NetBox...luck will be required!

squigley commented 4 years ago

Thanks for the reply. I think the difference in line numbers was to do with one being from the tar.gz and the other from git, which may be newer. The one from git has the issue on line 200. I made the modification you suggested, which seems to work, except now I'm having issues with it finding the nmap module, even though I have both python-nmap and nmap installed..

\# python ./nbscanner.py 
Traceback (most recent call last):
  File "./nbscanner.py", line 6, in <module>
    from nmap import PortScanner
ImportError: No module named nmap
[root@simon-test netbox-scanner]# python3 ./nbscanner.py 
Traceback (most recent call last):
  File "./nbscanner.py", line 6, in <module>
    from nmap import PortScanner
ImportError: cannot import name 'PortScanner'
# pip3 install python-nmap
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Requirement already satisfied: python-nmap in /usr/local/lib/python3.6/site-packages
[root@simon-test netbox-scanner]# pip3 install nmap
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Requirement already satisfied: nmap in /usr/local/lib/python3.6/site-packages
squigley commented 4 years ago

OK, I thought perhaps my issue was trying to run nbscanner.py instead of nbscanner, but that doesn't get me any further. That complains about missing module named ConfigParser (which I was able to install with no effect), and the same for "PortScanner", which doesn't exist as anything I can install with pip3. I don't know enough about python/pip to keep arguing with this, I guess I'll just write my own nmap scanner shell script and import it into netbox instead.

TeraHz commented 4 years ago

@squigley I had the same issue using the pip module. remove it with pip3 uninstall python-nmap and install it manually from the release tarball https://xael.org/pages/python-nmap-en.html - that made it work for me.

lopes commented 4 years ago

This module will discontinued in the new version and overall script will be simplified focusing on the standar library, see #18 .