2019-12-18 01:03:08 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# pylint: disable=C0103
|
|
|
|
|
|
|
|
"""
|
|
|
|
Filter out invalid domain names
|
|
|
|
"""
|
|
|
|
|
|
|
|
import database
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
# Parsing arguments
|
|
|
|
parser = argparse.ArgumentParser(
|
2019-12-19 08:05:05 +01:00
|
|
|
description="Filter out invalid domain name/ip addresses from a list.")
|
2019-12-18 01:03:08 +01:00
|
|
|
parser.add_argument(
|
|
|
|
'-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
|
2019-12-19 08:05:05 +01:00
|
|
|
help="Input file, one element per line")
|
2019-12-18 01:03:08 +01:00
|
|
|
parser.add_argument(
|
|
|
|
'-o', '--output', type=argparse.FileType('w'), default=sys.stdout,
|
2019-12-19 08:05:05 +01:00
|
|
|
help="Output file, one element per line")
|
2019-12-18 01:03:08 +01:00
|
|
|
parser.add_argument(
|
|
|
|
'-d', '--domain', action='store_true',
|
2019-12-19 08:05:05 +01:00
|
|
|
help="Can be domain name")
|
2019-12-18 01:03:08 +01:00
|
|
|
parser.add_argument(
|
|
|
|
'-4', '--ip4', action='store_true',
|
|
|
|
help="Can be IP4")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
for line in args.input:
|
2019-12-25 15:31:20 +01:00
|
|
|
line = line[:-1].lower()
|
2019-12-18 01:03:08 +01:00
|
|
|
if (args.domain and database.Database.validate_domain(line)) or \
|
|
|
|
(args.ip4 and database.Database.validate_ip4address(line)):
|
|
|
|
print(line, file=args.output)
|