summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristofer Hallin <kristofer@sunet.se>2021-10-07 17:19:39 +0200
committerKristofer Hallin <kristofer@sunet.se>2021-10-07 17:19:39 +0200
commit9dbf352a39ec4d346c9c2e43e63ebf7f8db50d33 (patch)
tree2e8901edab4379a52ed5008b071611979003cc02
parentc440b456c95a934078eb46ff809e249393eaec00 (diff)
Re-use random_string etc.
-rw-r--r--tools/feeder.py45
1 files changed, 18 insertions, 27 deletions
diff --git a/tools/feeder.py b/tools/feeder.py
index bc3c37e..f42fb6f 100644
--- a/tools/feeder.py
+++ b/tools/feeder.py
@@ -26,6 +26,21 @@ data = {
}
+def random_string(iters=1):
+ full_string = ''
+ random_string = ''
+
+ for i in range(iters):
+ for _ in range(10):
+ random_integer = random.randint(97, 97 + 26 - 1)
+ flip_bit = random.randint(0, 1)
+ random_integer = random_integer - 32 if flip_bit == 1 else random_integer
+ random_string += (chr(random_integer))
+ full_string += random_string
+
+ return full_string.lower()
+
+
def random_ipv4():
randint = random.randint(1, 0xffffffff)
@@ -71,7 +86,7 @@ def random_country():
def random_tld():
- domains = [
+ tlds = [
'.ac', '.ad', '.ae', '.af', '.ag', '.ai', '.al', '.am',
'.ao', '.aq', '.ar', '.as', '.at', '.au', '.aw', '.ax',
'.az', '.ba', '.bb', '.bd', '.be', '.bf', '.bg', '.bh',
@@ -105,16 +120,7 @@ def random_tld():
'.vu', '.wf', '.ws', '.ye', '.yt', '.za', '.zm', '.zw'
]
- tld = random.choice(domains)
- random_string = ''
-
- for _ in range(10):
- random_integer = random.randint(97, 97 + 26 - 1)
- flip_bit = random.randint(0, 1)
- random_integer = random_integer - 32 if flip_bit == 1 else random_integer
- random_string += (chr(random_integer))
-
- return f'{random_string}{tld}'.lower()
+ return random.choice(tlds)
def get_timestamp():
@@ -123,21 +129,6 @@ def get_timestamp():
return utc_datetime.strftime("%Y-%m-%dT%H:%M:%SUTC")
-def random_string(iters=1):
- full_string = ''
- random_string = ''
-
- for i in range(iters):
- for _ in range(10):
- random_integer = random.randint(97, 97 + 26 - 1)
- flip_bit = random.randint(0, 1)
- random_integer = random_integer - 32 if flip_bit == 1 else random_integer
- random_string += (chr(random_integer))
- full_string += random_string
-
- return full_string.lower()
-
-
def random_email():
return random_string() + '@' + random_string(2) + random_tld()
@@ -150,7 +141,7 @@ def generate_blob():
'asn': random_asn(),
'ptr': random_string(2),
'abuse_mail': random_email(),
- 'domain': random_string(),
+ 'domain': random_string() + random_tld(),
'timestamp_in_utc': get_timestamp(),
'producer_unique_keys': {
'subject_cn': 'unknown',