pucherot / Pi.Alert

WIFI / LAN intruder detector. Check the devices connected and alert you with unknown devices. It also warns of the disconnection of "always connected" devices
GNU General Public License v3.0
2.03k stars 126 forks source link

Not working with PiHole install in Proxmox/Ubuntu container installation #89

Open scoopdreams opened 3 years ago

scoopdreams commented 3 years ago

Hi there!

Thanks for this, it's really useful for a bird-eye's view on the status of connected devices.

However it does not seem to work on a PiHole installation (DHCP server is my Mikrotik router) inside a Proxmox container running Ubuntu 18.04. Seems like there's some issue with the arp-scan routines.

sudo python3 ~/pialert/back/pialert.py 1

Pi.Alert 2.70 (2021-02-01)
---------------------------------------------------------
Scan Devices
    ScanCycle: 1
    Timestamp: 2021-03-29 14:09:00

Scanning...
    arp-scan Method...
Traceback (most recent call last):
  File "/root/pialert/back/pialert.py", line 1441, in <module>
    sys.exit(main())       
  File "/root/pialert/back/pialert.py", line 85, in main
    res = scan_network()
  File "/root/pialert/back/pialert.py", line 359, in scan_network
    arpscan_devices = execute_arpscan (arpscan_retries)
  File "/root/pialert/back/pialert.py", line 456, in execute_arpscan
    arpscan_output = subprocess.check_output (arpscan_args, universal_newlines=True)
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 425, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/usr/lib/python3.6/subprocess.py", line 850, in communicate
    stdout = self.stdout.read()
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 715: ordinal not in range(128)

Just feedback for your consideration - hope you manage to get this resolved! Looking forward to using it.

pucherot commented 3 years ago

Probably you are using a 7 bit charset.

Check the values of the locale command

And set an 8-bit charset for the user that executes Pi.Alert, for example export LANG=en_US.UTF-8

Perhaps you need to reconfigure locale package:

sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales

In next version I will try to force charset in Pi.Alert python script:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
scoopdreams commented 3 years ago

Thanks for this. I've tried reconfigured my locales (along with a reboot), to

$ locale

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

$ localectl status

System Locale: LANG=en_US.UTF-8
VC Keymap: n/a
X11 Layout: us
X11 Model: pc105

ARP scan is verified working

$ arp-scan --localnet

Interface: eth0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.9 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.1.1     xx:xx:xx:xx:xx:xx     Routerboard.com
192.168.1.3     xx:xx:xx:xx:xx:xx       Elitegroup Computer Systems Co.,Ltd.
192.168.1.5     xx:xx:xx:xx:xx:xx       (Unknown)
192.168.1.8     xx:xx:xx:xx:xx:xx       (Unknown)
192.168.1.9    xx:xx:xx:xx:xx:xx       (Unknown)
192.168.1.10    xx:xx:xx:xx:xx:xx       Mellanox Technologies, Inc.
...

Still having the issue albeit with at line 321 instead of 25.

$ python3 ~/pialert/back/pialert.py 1

Pi.Alert 2.70 (2021-02-01)
---------------------------------------------------------
Scan Devices
    ScanCycle: 1
    Timestamp: 2021-04-19 07:20:00

Scanning...
    arp-scan Method...
Traceback (most recent call last):
  File "/root/pialert/back/pialert.py", line 1441, in <module>
    sys.exit(main())       
  File "/root/pialert/back/pialert.py", line 85, in main
    res = scan_network()
  File "/root/pialert/back/pialert.py", line 359, in scan_network
    arpscan_devices = execute_arpscan (arpscan_retries)
  File "/root/pialert/back/pialert.py", line 456, in execute_arpscan
    arpscan_output = subprocess.check_output (arpscan_args, universal_newlines=True)
  File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.6/subprocess.py", line 425, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/usr/lib/python3.6/subprocess.py", line 850, in communicate
    stdout = self.stdout.read()
  File "/usr/lib/python3.6/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 647: invalid start byte