-
Notifications
You must be signed in to change notification settings - Fork 3
/
internet.gleam
207 lines (174 loc) · 4.01 KB
/
internet.gleam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import gleam/int
import gleam/pair
import gleam/list
import gleam/string
import blah/name
import blah/en/word
import blah/utils.{get_random_item}
import blah/en/string as blah_string
const email_domains = [
"aol.com", "gmail.com", "hotmail.com", "live.com", "mail.ru", "msn.com",
"outlook.com", "proton.me", "protonmail.com", "yahoo.com", "ymail.com",
]
const domain_suffixes = [
"co", "com", "edu", "gov", "int", "io", "mil", "net", "org",
]
const protocols = ["http", "https"]
const status_codes = [
#("informational", [100, 101, 102, 103]),
#("successful", [200, 201, 202, 203, 204, 205, 206, 207, 208, 226]),
#("redirection", [300, 301, 302, 303, 304, 305, 306, 307, 308]),
#(
"client_error",
[
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,
415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428, 429, 431, 451,
],
),
#("server_error", [500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511]),
]
pub type HTTPStatusClass {
Informational
Successful
Redirection
ClientError
ServerError
}
pub fn username() {
let adjective = word.adjective()
let last_name = name.last_name()
let nonce = int.random(4, 2048)
case nonce % 4 {
0 ->
[adjective, last_name]
|> string.join("")
1 ->
[adjective, string.lowercase(last_name)]
|> string.join(".")
2 ->
[adjective, string.lowercase(last_name)]
|> string.join("-")
3 ->
[adjective, string.lowercase(last_name)]
|> string.join("_")
}
}
pub fn email() {
let email_domain = get_random_item(email_domains)
[username(), email_domain]
|> string.join("@")
}
pub fn password() {
let length = int.random(8, 32)
blah_string.alphanumeric(length)
}
pub fn passphrase() {
[
word.adjective(),
name.first_name()
|> string.lowercase(),
word.verb(),
word.adverb(),
]
|> string.join(" ")
}
pub fn domain_name() {
let adjective = word.adjective()
let noun = word.noun()
let nonce = int.random(4, 2048)
let hostname = case nonce % 3 {
0 ->
[adjective, noun]
|> string.join(".")
1 ->
[adjective, noun]
|> string.join("-")
2 ->
[adjective, noun]
|> string.join("_")
}
let suffix = get_random_item(domain_suffixes)
[hostname, suffix]
|> string.join(".")
}
pub fn url() {
let protocol = get_random_item(protocols)
[protocol, "://", domain_name()]
|> string.join("")
}
pub fn ip_v4() {
list.repeat("", 4)
|> list.map(fn(_) { int.random(0, 256) })
|> list.map(int.to_string)
|> string.join(".")
}
pub fn ip_v6() {
list.repeat("", 8)
|> list.map(fn(_) { int.random(0, 65_536) })
|> list.map(fn(field) {
field
|> int.to_base16
|> string.lowercase
})
|> string.join(":")
}
pub fn mac() {
list.repeat("", 6)
|> list.map(fn(_) { int.random(0, 256) })
|> list.map(fn(field) {
field
|> int.to_base16
|> string.lowercase
})
|> string.join(":")
}
pub fn long_hex_color() {
[
"#",
..list.repeat("", 3)
|> list.map(fn(_) { int.random(0, 256) })
|> list.map(fn(field) {
field
|> int.to_base16
|> string.lowercase
|> string.pad_left(2, "0")
})
]
|> string.join("")
}
pub fn short_hex_color() {
[
"#",
..list.repeat("", 3)
|> list.map(fn(_) { int.random(0, 15) })
|> list.map(fn(field) {
field
|> int.to_base16
|> string.lowercase
})
]
|> string.join("")
}
pub fn hex_color() {
let nonce = int.random(4, 2048)
case nonce % 2 {
0 -> long_hex_color()
1 -> short_hex_color()
}
}
pub fn status_code() {
let #(_, codes) = get_random_item(status_codes)
get_random_item(codes)
}
pub fn status_code_in_class(class: HTTPStatusClass) {
let class_string = case class {
Informational -> "informational"
Successful -> "successful"
Redirection -> "redirection"
ClientError -> "client_error"
ServerError -> "server_error"
}
let [#(_, codes)] =
list.filter(status_codes, fn(kv) { pair.first(kv) == class_string })
get_random_item(codes)
}