ptrstream

- Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.acid.vegas/-c.git
Log | Files | Refs | Archive | README

commit 581efb8f6da3621cb059e546757e02fc94f9fc60
parent 1b3fb6b722c40531f72c893e14c6e15b137df450
Author: acidvegas <acid.vegas@acid.vegas>
Date: Thu, 23 Nov 2023 04:39:04 -0500

Easier theming of colors via variables

Diffstat:
Mptrstream.py | 41++++++++++++++++++++++++++---------------

1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/ptrstream.py b/ptrstream.py
@@ -14,6 +14,17 @@ except ImportError:
 	raise ImportError('missing required \'aiodns\' library (pip install aiodns)')
 
 
+# Colors
+class colors:
+	ip = '\033[35m'
+	ip_match = '\033[96m'
+	ptr = '\033[93m'
+	spooky = '\033[31m'
+	invalid = '\033[90m'
+	reset = '\033[0m'
+	separator = '\033[90m'
+
+
 def get_dns_servers() -> list:
 	'''Get a list of DNS servers to use for lookups.'''
 	source = urllib.request.urlopen('https://public-dns.info/nameservers.txt')
@@ -87,27 +98,27 @@ async def main():
 				for task in done:
 					ip, result = task.result()
 					if result:
-						if result in ('127.0.0.1','localhost'):
-							print(f'\033[35m{ip.ljust(15)}\033[0m \033[90m-> {result}\033[0m')
+						if result in ('127.0.0.1', 'localhost'):
+							print(f'{colors.ip}{ip.ljust(15)}{colors.reset} {colors.separator}-> {result}{colors.reset}')
 						elif ip in result:
-							result = result.replace(ip, f'\033[96m{ip}\033[93m')
+							result = result.replace(ip, f'{colors.ip_match}{ip}{colors.ptr}')
 						elif (daship := ip.replace('.', '-')) in result:
-							result = result.replace(daship, f'\033[96m{daship}\033[93m')
-							print(f'\033[35m{ip.ljust(15)}\033[0m \033[90m->\033[0m \033[93m{result}\033[0m')
+							result = result.replace(daship, f'{colors.ip_match}{daship}{colors.ptr}')
+							print(f'{colors.ip}{ip.ljust(15)}{colors.reset} {colors.separator}->{colors.reset} {colors.ptr}{result}{colors.reset}')
 						elif (revip := '.'.join(ip.split('.')[::-1])) in result:
-							result = result.replace(revip, f'\033[96m{revip}\033[93m')
-							print(f'\033[35m{ip.ljust(15)}\033[0m \033[90m->\033[0m \033[93m{result}\033[0m')
+							result = result.replace(revip, f'{colors.ip_match}{revip}{colors.ptr}')
+							print(f'{colors.ip}{ip.ljust(15)}{colors.reset} {colors.separator}->{colors.reset} {colors.ptr}{result}{colors.reset}')
 						elif result.endswith('.gov') or result.endswith('.mil'):
-							result = result.replace('.gov', f'\033[31m.gov\033[0m')
-							result = result.replace('.mil', f'\033[31m.gov\033[0m')
-							print(f'\033[35m{ip.ljust(15)}\033[0m \033[90m->\033[0m \033[93m{result}\033[0m')
+							result = result.replace('.gov', f'{colors.spooky}.gov{colors.reset}')
+							result = result.replace('.mil', f'{colors.spooky}.gov{colors.reset}')
+							print(f'{colors.ip}{ip.ljust(15)}{colors.reset} {colors.separator}->{colors.reset} {colors.ptr}{result}{colors.reset}')
 						elif '.gov.' in result or '.mil.' in result:
-							result = result.replace('.gov.', f'\033[31m.gov.\033[0m')
-							result = result.replace('.mil.', f'\033[31m.mil.\033[0m')
-							print(f'\033[35m{ip.ljust(15)}\033[0m \033[90m->\033[0m \033[93m{result}\033[0m')
+							result = result.replace('.gov.', f'{colors.spooky}.gov.{colors.reset}')
+							result = result.replace('.mil.', f'{colors.spooky}.mil.{colors.reset}')
+							print(f'{colors.ip}{ip.ljust(15)}{colors.reset} {colors.separator}->{colors.reset} {colors.ptr}{result}{colors.reset}')
 						else:
-							scary = ('.gov')
-							print(f'\033[35m{ip.ljust(15)}\033[0m \033[90m->\033[0m \033[93m{result}\033[0m')
+							print(f'{colors.ip}{ip.ljust(15)}{colors.reset} {colors.separator}->{colors.reset} {colors.ptr}{result}{colors.reset}')
+
 						results_cache.append(f'{ip}:{result}')
 					if len(results_cache) >= 1000:
 						stamp = time.strftime('%Y%m%d')