How to limit and randomize the web output?

Question:

Is there a way where I can limit a website generaot output and make the output more randomize since it outputs the name alphabetically. I tried to use limit and randomize i, but it doesn’t seem to work

import re
from selenium import webdriver
import os
import json
import requests
import validators
from urllib.request import Request, urlopen
import numpy as np
import random 
import whois
import pandas as pd
import itertools

Combined = open("dictionaries/Combined.txt", 'r', encoding="utf-8")
Example = open("dictionaries/examples.txt", 'w', encoding="utf-8")

with open("dictionaries/Combined.txt") as i:
    Test = [line.rstrip() for line in i]

This is what’s inside the Combined.txt

Combined text file

delimeters = ['','-', '.']

output_count = 100
web = 'web'
suffix = 'co.id'
for x in range(output_count):
    output = []
    for combo in itertools.combinations(Test, 2):
        out = ''
        for i, d in enumerate(delimeters):
            out = d.join(combo)
            out = delimeters[i-1].join([out, web])
            addr = '.'.join([out, suffix])
            output.append(random.choice(out))
            Example.write(addr+'n')

with open("dictionaries/examples.txt") as f:
websamples = [line.rstrip() for line in f]

This is the output that i get.

websamples

websamples

Websamples 2

As you see at the image, the web generator outputs too many web domain generator it doesn’t even show the rest of the output in Jupyter Notebook. Is there a way where the web domain generator doesn’t output the web alphabetically and mix it up and limits the number of outputs that I want? for example i want to limit it to just a 100 with randomize outputs instead of outputting possible combination domain name and outputs it alphabetically

Thanks

Asked By: Tsukuru

||

Answers:

Using the built in random library is going to be your friend here. For example if you want to select 100 random elements from a list you can use the random.sample function as demonstrated below:

nums = list(range(1000))
random_nums = random.sample(nums, 100)
print(random_nums)

You can read more about this function here: https://docs.python.org/3/library/random.html#random.sample

Answered By: Zach Bellay

Ignoring the Test list of course that should generate 100 addresses as randomly put together as possible.

Try this:

import random
#Test = ['auth', 'access', 'account', 'admin', 'agree', 'blue', 'business', 'cdn', 'cl', 'click', 'confirm', 'download', 'enroll', 'find', 'group', 'install', 'login', 'mobile', 'my', 'online', 'pay', 'portal', 'register']
delimeters = ['','-', '.']
web, suffix = 'web', 'co.id'
output = []
for i in range(100):
    prefix = random.choice(delimeters).join([random.choice(Test), random.choice(Test)])
    out = random.choice(delimeters).join([prefix, web])
    addr = '.'.join([out, suffix])
    output.append(addr)
    Example.write(addr+'n')

OUTPUT:

  [
    "blue.auth.web.co.id",
    "pay.my-web.co.id",
    "click.install-web.co.id",
    "clickgroupweb.co.id",
    "businessinstallweb.co.id",
    "portal.install.web.co.id",
    "click.online-web.co.id",
    "accesscl.web.co.id",
    "admin-blue-web.co.id",
    "register-group.web.co.id",
    "business-enroll-web.co.id",
    "download-payweb.co.id",
    "portal.cl-web.co.id",
    "paybusiness.web.co.id",
    "business.click-web.co.id",
    "downloadblue-web.co.id",
    "businesslogin-web.co.id",
    "my.admin.web.co.id",
    "login.my.web.co.id",
    "mobileonlineweb.co.id",
    "cl-login.web.co.id",
    "business.account.web.co.id",
    "pay.click.web.co.id",
    "group.enrollweb.co.id",
    "agreecdn.web.co.id",
    "enroll-auth.web.co.id",
    "confirm.confirmweb.co.id",
    "account.register.web.co.id",
    "admincl.web.co.id",
    "clickmobile-web.co.id",
    "registerdownload.web.co.id",
    "download.admin.web.co.id",
    "business.my-web.co.id",
    "account-download-web.co.id",
    "auth-account.web.co.id",
    "login-clickweb.co.id",
    "businessregister.web.co.id",
    "mobile.accountweb.co.id",
    "cl.groupweb.co.id",
    "payagree-web.co.id",
    "portal-cdnweb.co.id",
    "online.my-web.co.id",
    "pay-cdnweb.co.id",
    "accountgroupweb.co.id",
    "pay.confirmweb.co.id",
    "confirm.cl-web.co.id",
    "group-access-web.co.id",
    "install-payweb.co.id",
    "enroll.pay.web.co.id",
    "business.mobileweb.co.id",
    "accessclickweb.co.id",
    "login.onlineweb.co.id",
    "clickdownload-web.co.id",
    "blueinstall.web.co.id",
    "installlogin-web.co.id",
    "portalloginweb.co.id",
    "myconfirmweb.co.id",
    "admin-authweb.co.id",
    "portal-admin-web.co.id",
    "cl.my-web.co.id",
    "admin.register.web.co.id",
    "auth-blueweb.co.id",
    "admin.blueweb.co.id",
    "my-accountweb.co.id",
    "auth.installweb.co.id",
    "portal-install-web.co.id",
    "downloadmobile-web.co.id",
    "online.blue.web.co.id",
    "blue.find.web.co.id",
    "group-blueweb.co.id",
    "adminclickweb.co.id",
    "cdnconfirm.web.co.id",
    "agree-click.web.co.id",
    "cl.enroll.web.co.id",
    "login.admin-web.co.id",
    "groupbusinessweb.co.id",
    "agree.cdn-web.co.id",
    "my-groupweb.co.id",
    "clagree.web.co.id",
    "click.authweb.co.id",
    "enrollfind.web.co.id",
    "find-findweb.co.id",
    "click-cdn-web.co.id",
    "cdnagree.web.co.id",
    "loginmobileweb.co.id",
    "paybusiness-web.co.id",
    "online.install-web.co.id",
    "my-clweb.co.id",
    "group-install.web.co.id",
    "findenrollweb.co.id",
    "cl-accessweb.co.id",
    "register.click.web.co.id",
    "register-business.web.co.id",
    "portal-account.web.co.id",
    "admin-accessweb.co.id",
    "confirmloginweb.co.id",
    "loginclick.web.co.id",
    "agree-group-web.co.id",
    "click-group.web.co.id",
    "confirm-enroll.web.co.id"
  ]
Answered By: Alexander
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.