Generates a host list of first-party trackers for ad-blocking.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.1KB

  1. #!/usr/bin/env python3
  2. # pylint: disable=C0103
  3. """
  4. Filter out invalid domain names
  5. """
  6. import database
  7. import argparse
  8. import sys
  9. if __name__ == '__main__':
  10. # Parsing arguments
  11. parser = argparse.ArgumentParser(
  12. description="Filter out invalid domain name/ip addresses from a list.")
  13. parser.add_argument(
  14. '-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
  15. help="Input file, one element per line")
  16. parser.add_argument(
  17. '-o', '--output', type=argparse.FileType('w'), default=sys.stdout,
  18. help="Output file, one element per line")
  19. parser.add_argument(
  20. '-d', '--domain', action='store_true',
  21. help="Can be domain name")
  22. parser.add_argument(
  23. '-4', '--ip4', action='store_true',
  24. help="Can be IP4")
  25. args = parser.parse_args()
  26. for line in args.input:
  27. line = line[:-1].lower()
  28. if (args.domain and database.Database.validate_domain(line)) or \
  29. (args.ip4 and database.Database.validate_ip4address(line)):
  30. print(line, file=args.output)