So I have this python file I created on windows:
import sqlite3
import getmac
import nmap
nm = nmap.PortScanner()
prevAmount = 0
while True:
nm.scan(hosts='192.168.1.0/24', arguments='-n -sP -PE -PA21,23,80,3389')
hosts_list = nm.all_hosts()
hosts_list.remove('192.168.1.1')
print(hosts_list)
if len(hosts_list) > prevAmount:
for host in hosts_list:
mac = getmac.get_mac_address(ip=host)
connection = sqlite3.connect('OpenSesame.db')
cursor = connection.cursor()
cursor.execute("SELECT EXISTS(SELECT 1 FROM tblDevices WHERE DeviceMAC ='" mac "');")
bExists = cursor.fetchone()
if bExists[0] == 1:
cursor.execute("SELECT DeviceName FROM tblDevices WHERE DeviceMAC ='" mac "';")
persoon = cursor.fetchone()
print(persoon[0])
prevAmount = len(hosts_list)
elif len(hosts_list) < prevAmount:
prevAmount = 0
I'm currently stuck trying to implement it on a Raspberry Pi, obviously running Linux. The complete output I get is:
['192.168.1.17', '192.168.1.55', '192.168.1.56', '192.168.1.59', '192.168.1.70']
Traceback (most recent call last):
File "RelayOpenSesame.py", line 19, in <module>
cursor.execute("SELECT EXISTS(SELECT 1 FROM tblDevices WHERE DeviceMAC ='" mac "');")
TypeError: can only concatenate str (not "NoneType") to str
This ONLY happens on Linux, not on windows.
I've also noticed when connecting a device to the network that is in fact in the database, that it does print out the name, which is done by line 23: print(persoon[0])
So, the program runs through line 19 that causes the error, and probably only after the last line it throws the error stopping the program.
Any idea why this might be?
CodePudding user response:
As it become clear from the comments - the problem is with host/local ip for which getmac.get_mac_address()
returns None
. I also confirmed that on Linux.
Looking at this issue - it's known bug/limitation of the package - it does not work for host ip on Linux. Check the discussion for more info.
You can use local interface name though.