[scanner] implement the --list flag

This commit is contained in:
fnux 2021-04-22 10:20:49 +02:00
commit bb24d632d6
No known key found for this signature in database
GPG key ID: 4502C902C00A1E12
3 changed files with 67 additions and 17 deletions

View file

@ -132,6 +132,23 @@ class Scanner(object):
with open(fname, "w") as fd:
fd.write(f"{now}\n")
def list(self):
hosts = dict()
for linklocal_addr in os.listdir(self.outdir):
workdir = os.path.join(self.outdir, linklocal_addr)
# We ignore any (unexpected) file in this directory.
if os.path.isdir(workdir):
last_seen='-'
last_seen_file = os.path.join(workdir, 'last_seen')
if os.path.isfile(last_seen_file):
with open(last_seen_file, "r") as fd:
last_seen = fd.readline()
hosts[linklocal_addr] = {'last_seen': last_seen}
return hosts
def config(self):
"""
Configure a host