InternetHostName()

master
Charles Iliya Krempeaux 2024-08-26 15:53:38 -07:00
parent 1f5dcd5b8a
commit 5b0908e842
3 changed files with 205 additions and 0 deletions

View File

@ -21,6 +21,11 @@ func HTMLFile() fs.File {
return Default.HTMLFile()
}
// InternetHostName returns an arbitrary Internet hostname.
func InternetHostName() string {
return Default.InternetHostName()
}
// NetAddr returns an arbitrary net.Addr.
func NetAddr() net.Addr {
return Default.NetAddr()

View File

@ -0,0 +1,44 @@
package arbitrary
import (
"fmt"
"strings"
)
// InternetHostName returns an arbitrary Internet hostname.
func (arb T) InternetHostName() string {
var partchars string = "0123456789abcdefghijklmnopqrstuvwxyz"
var tld string = tlds[arb.randomness.Intn(len(tlds))]
var parts []string
{
var numparts int = 1 + arb.randomness.Intn(3)
for i:=0; i<numparts; i++ {
var part string
if arb.Bool() {
var partlen int = 1 + arb.randomness.Intn(63)
part = arb.String(partlen, partchars)
} else {
part = wordsEnglish[arb.randomness.Intn(len(wordsEnglish))]
if 0 == (arb.randomness.Int() % 10) {
part += fmt.Sprintf("-%d", arb.randomness.Intn(1000))
}
}
parts = append(parts, part)
}
}
parts = append(parts, tld)
return strings.Join(parts, ".")
}

156
tlds.go 100644
View File

@ -0,0 +1,156 @@
package arbitrary
var tlds = []string{
"academy",
"accountant",
"accountants",
"active",
"actor",
"ads",
"adult",
"aero",
"africa",
"agency",
"amazon",
"analytics",
"apartments",
"app",
"apple",
"art",
"arpa",
"audible",
"author",
"auto",
"autos",
"baby",
"banana",
"band",
"bank",
"bbs",
"bio",
"black",
"blog",
"blue",
"boo",
"book",
"bot",
"call",
"camp",
"car",
"cars",
"chat",
"cherry",
"city",
"com",
"cool",
"click",
"computer",
"data",
"day",
"dev",
"directory",
"diy",
"dot",
"edu",
"fail",
"farm",
"fire",
"fish",
"free",
"fun",
"fyi",
"game",
"games",
"gov",
"green",
"group",
"int",
"help",
"here",
"host",
"info",
"kim",
"land",
"link",
"live",
"lol",
"meet",
"mil",
"monster",
"name",
"net",
"network",
"ninja",
"now",
"one",
"open",
"org",
"page",
"pay",
"phone",
"photo",
"photography",
"photos",
"pics",
"pictures",
"pizza",
"plus",
"post",
"pub",
"radio",
"read",
"red",
"report",
"rocks",
"room",
"run",
"save",
"science",
"select",
"show",
"site",
"social",
"software",
"solar",
"song",
"spot",
"store",
"stream",
"studio",
"style",
"sucks",
"support",
"talk",
"taxi",
"team",
"tech",
"technology",
"tel",
"tips",
"today",
"tools",
"top",
"town",
"toys",
"travel",
"trust",
"tube",
"video",
"vision",
"webcam",
"website",
"wedding",
"whoswho",
"wiki",
"win",
"work",
"works",
"world",
"wow",
"wtf",
"you",
"zero",
"zip",
"zone",
"xxx",
}