Skip to content

Instantly share code, notes, and snippets.

@ericmoritz
Last active December 17, 2015 14:19
Show Gist options
  • Save ericmoritz/5623691 to your computer and use it in GitHub Desktop.
Save ericmoritz/5623691 to your computer and use it in GitHub Desktop.
attempt to find a easy to say domain

I wanted to find a domain that could easily be spelled without confusion.

import random
import itertools
letters = "qwxfhlrs"
for item in itertools.permutations(letters, 4):
print "{}.com".format("".join(item))
#!/usr/bin/env escript
%% -*- erlang -*-
%% -smp enable
-mode(compile).
domain_available(WhoisResult) ->
re:run(WhoisResult, "No match for") =:= nomatch.
whois(Domain) ->
os:cmd(["whois ", Domain]).
mapper(Domain) ->
Result = whois(Domain),
case domain_available(Result) of
true ->
{ok, Domain};
false ->
nothing
end.
read_lines(FH, Acc) ->
case file:read_line(FH) of
{ok, Line} ->
StrippedLine = string:strip(Line, right, $\n),
read_lines(FH, [StrippedLine|Acc]);
eof ->
Acc
end.
output([]) ->
ok;
output([nothing|Rest]) ->
output(Rest);
output([{ok, Domain}|Rest]) ->
io:format("~s~n", [Domain]),
output(Rest).
main([DomainFile]) ->
{ok, FH} = file:open(DomainFile, [read]),
Domains = read_lines(FH, []),
file:close(FH),
Results = plists:map(fun mapper/1, Domains),
output(Results).
@ericmoritz
Copy link
Author

Took 28s to do whois queries on 1680 domains.

@gfranxman
Copy link

Where did you get your plists from? I tried it from https://code.google.com/p/plists/source/browse/#svn%2Ftrunk but I get exceptions on osx lion with R16B and ubuntu precise with r14b04.

Using regular lists:map/2 works but is predictably slow. Using plists, I get:

escript: exception exit: {emfile,[{erlang,open_port,
                             [{spawn,"/bin/sh -s unix:cmd 2>&1"},
                              [stream]]},
                     {os,start_port_srv_handle,1},
                     {os,start_port_srv_loop,0}]}
in function  plists:handle_error/3
in call from plists:local_runmany/3
in call from whois_erl__escript__1369__282284__13128:main/1
in call from escript:run/2
in call from escript:start/1
in call from init:start_it/1
in call from init:start_em/1

Ever seen that?

@gfranxman
Copy link

Found it. Just too many domains at a time. At least on my machine, it gets maxed out at 511 domains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment