From 7a1a728a5a854d3691476d0c229fedc8a22a03cc Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Wed, 11 Aug 2021 18:50:47 -0700 Subject: [PATCH] generate different, pseudo-random subdomains every week --- respodns/util.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/respodns/util.py b/respodns/util.py index f41ef1f..afff64e 100644 --- a/respodns/util.py +++ b/respodns/util.py @@ -14,17 +14,24 @@ def right_now(): return datetime.now(timezone.utc) -def nonsense_consistent(domain): +def nonsense_consistent(domain, weekly=True): + from datetime import datetime, timezone from random import Random from string import ascii_lowercase from zlib import crc32 - rng = Random(crc32(domain.encode("utf-8"))) + if weekly: + week = datetime.now(timezone.utc).isocalendar().week + week_bytes = bytes((week, week, week, week)) + seed = crc32(week_bytes + domain.encode("utf-8")) + else: + seed = crc32(domain.encode("utf-8")) + rng = Random(seed) length = rng.choices((9, 10, 11, 12), (4, 5, 3, 2))[0] return "".join(rng.choice(ascii_lowercase) for i in range(length)) -def concat_nonsense(domain): - return nonsense_consistent(domain) + "." + domain +def concat_nonsense(domain, weekly=True): + return nonsense_consistent(domain, weekly=weekly) + "." + domain def head(n, it):