/usr/share/doc/denyhosts/examples/scripts/restricted_from_invalid.py is in denyhosts 2.10-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #!/usr/bin/env python
import os, sys
def usage():
print "%s WORK_DIR [num_results]" % sys.argv[0]
sys.exit(1)
try:
work_dir = sys.argv[1]
except IndexError:
print "you must specify your DenyHosts WORK_DIR"
usage()
try:
num = int(sys.argv[2])
except IndexError:
num = 10
fname = os.path.join(work_dir, "users-invalid")
try:
fp = open(fname, "r")
except IOError:
print fname, "does not exist"
sys.exit(1)
d = {}
for line in fp:
try:
foo = line.split(":")
username = foo[0]
attempts = int(foo[1])
# timestamp = foo[2].strip()
except Exception:
continue
l = d.get(attempts, [])
l.append(username)
d[attempts] = l
fp.close()
keys = d.keys()
keys.sort()
keys.reverse()
i = 0
for key in keys:
l = d.get(key)
for username in l:
i += 1
print username
if i >= num: break
if i >= num: break
|