summaryrefslogtreecommitdiff
path: root/tools/feeder.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/feeder.py')
-rw-r--r--tools/feeder.py169
1 files changed, 0 insertions, 169 deletions
diff --git a/tools/feeder.py b/tools/feeder.py
deleted file mode 100644
index cf52c36..0000000
--- a/tools/feeder.py
+++ /dev/null
@@ -1,169 +0,0 @@
-import requests
-import random
-import socket
-import ipaddress
-import datetime
-import itertools
-import json
-import threading
-import time
-
-
-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)
-
- return str(ipaddress.IPv4Address(randint))
-
-
-def random_ipv6():
- randint = random.randint(0, 2**128-1)
-
- return str(ipaddress.IPv6Address(randint))
-
-
-def random_port():
- return random.randint(1, 65536)
-
-
-def random_asn():
- randint = random.randint(1, 65536)
-
- return f'AS{randint}'
-
-
-def random_country():
- countries = [
- 'AF', 'AL', 'DZ', 'AD', 'AO', 'AI', 'AQ', 'AR', 'AM', 'AW',
- 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM',
- 'BT', 'BO', 'BQ', 'BW', 'BR', 'BG', 'BI', 'KH', 'CM', 'CA', 'TD', 'CL',
- 'CN', 'CO', 'HR', 'CU', 'CW', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'EC', 'EG',
- 'GU', 'ER', 'EE', 'SZ', 'ET', 'FJ', 'FI', 'FR', 'GA', 'GH', 'GE', 'DE',
- 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GG', 'GN', 'GW', 'GY',
- 'HT', 'HN', 'HU', 'IS', 'IN', 'ID', 'IQ', 'IE', 'IL', 'IT', 'JM', 'JP',
- 'JE', 'JO', 'KZ', 'KE', 'KI', 'KW', 'KG', 'LV', 'LB', 'LS', 'LR', 'LY',
- 'LI', 'LT', 'LU', 'MO', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MQ', 'MR',
- 'MU', 'YT', 'MX', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR',
- 'NP', 'NI', 'NG', 'NU', 'NO', 'OM', 'PK', 'PW', 'PA', 'PY', 'PE', 'PN',
- 'PL', 'PT', 'QA', 'RO', 'RW', 'RE', 'WS', 'SN', 'RS', 'SC', 'SG', 'SK',
- 'SI', 'SO', 'ES', 'SR', 'SE', 'CH', 'TJ', 'TH', 'TL', 'TG', 'TK', 'TO',
- 'TN', 'TR', 'TM', 'TV', 'UG', 'UA', 'UY', 'UZ', 'VU', 'YE', 'ZM', 'ZW',
- 'AX'
- ]
-
- return random.choice(countries)
-
-
-def random_tld():
- 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',
- '.bi', '.bj', '.bm', '.bn', '.bo', '.bq', '.br', '.bs',
- '.bt', '.bw', '.by', '.bz', '.ca', '.cc', '.cd', '.cf',
- '.cg', '.ch', '.ci', '.ck', '.cl', '.cm', '.cn', 'Als',
- '.co', '.cr', '.cu', '.cv', '.cw', '.cx', '.cy', '.cz',
- '.de', '.dj', '.dk', '.dm', '.do', '.dz', '.ec', '.ee',
- '.eg', '.eh', '.er', '.es', '.et', '.eu', '.fi', '.fj',
- '.fk', '.fm', '.fo', '.fr', '.ga', '.gd', '.ge', '.gf',
- '.gg', '.gh', '.gi', '.gl', '.gm', '.gn', '.gp', '.gq',
- '.gr', '.gs', '.gt', '.gu', '.gw', '.gy', '.hk', '.hm',
- '.hn', '.hr', '.ht', '.hu', '.id', '.ie', '.il', '.im',
- '.in', '.io', '.iq', '.ir', '.is', '.it', '.je', '.jm',
- '.jo', '.jp', '.ke', '.kg', '.kh', '.ki', '.km', '.kn',
- '.kp', '.kr', '.kw', '.ky', '.kz', '.la', '.lb', '.lc',
- '.li', '.lk', '.lr', '.ls', '.lt', '.lu', '.lv', '.ly',
- '.ma', '.mc', '.md', '.me', '.mg', '.mh', '.mk', '.ml',
- '.mm', '.mn', '.mo', '.mp', '.mq', '.mr', '.ms', '.mt',
- '.mu', '.mv', '.mw', '.mx', '.my', '.mz', '.na', '.nc',
- '.ne', '.nf', '.ng', '.ni', '.nl', '.no', 'Als', '.np',
- '.nr', '.nu', '.nz', '.om', '.pa', '.pe', '.pf', '.pg',
- '.ph', '.pk', '.pl', '.pm', '.pn', '.pr', '.ps', '.pt',
- '.pw', '.py', '.qa', '.re', '.ro', '.rs', '.ru', '.rw',
- '.sb', '.sc', '.sd', '.se', '.sg', '.sh', '.si', '.sk',
- '.sl', '.sm', '.sn', '.so', '.sr', '.ss', '.st', '.su',
- '.sv', '.sx', '.sy', '.sz', '.tc', '.td', '.tf', '.tg',
- '.th', '.tj', '.tk', '.tl', '.tm', '.tn', '.to', '.tr',
- '.tt', '.tv', '.tw', '.tz', '.ua', '.ug', '.uk', '.us',
- '.uy', '.uz', '.va', '.vc', '.ve', '.vg', '.vi', '.vn',
- '.vu', '.wf', '.ws', '.ye', '.yt', '.za', '.zm', '.zw'
- ]
-
- return random.choice(tlds)
-
-
-def get_timestamp():
- utc_datetime = datetime.datetime.utcnow()
-
- return utc_datetime.strftime("%Y-%m-%dT%H:%M:%SUTC")
-
-
-def random_email():
- return random_string() + '@' + random_string(2) + random_tld()
-
-
-def generate_blobs(nr_blobs=1):
- blobs = []
-
- for _ in range(nr_blobs):
- blobs.append({
- 'ip': random_ipv4(),
- 'port': random_port(),
- 'whois_description': random_string(2),
- 'asn': random_asn(),
- 'asn_country_code': random_country(),
- 'ptr': random_string(2),
- 'abuse_mail': random_email(),
- 'domain': "sunet.se",
- 'timestamp_in_utc': get_timestamp(),
- 'user_presentation': {
- 'description': 'A presentation of the observation as a whole (optional)',
- 'data': {
- random_string(): {
- 'display_name': random_string(),
- 'data': random_string(),
- 'description': random_string(),
- },
- random_string(): {
- 'display_name': random_string(),
- 'data': random_string(),
- },
- random_string(): {
- 'display_name': random_string(),
- 'data': random_string(),
- },
- }
- },
- })
-
- return blobs
-
-
-def send_blob():
- url = 'http://localhost:8000/sc/v0/add'
-
- blobs = generate_blobs(10000)
-
- start = time.process_time()
- requests.post(url, json=blobs)
- print(time.process_time() - start)
-
-
-if __name__ == '__main__':
- for _ in range(100):
- send_blob()
- print('Saved 10000 docs')