0
# Internet and Network Data
1
2
Generate internet-related data including IP addresses, domains, URLs, user agents, and network protocols with proper formatting and validation for testing web applications and network systems.
3
4
## Capabilities
5
6
### Email and Domain Generation
7
8
Generate email addresses and domain names with realistic formatting.
9
10
```python { .api }
11
class Internet(BaseProvider):
12
13
def top_level_domain(self, tld_type: TLDType = TLDType.CCTLD) -> str:
14
"""
15
Generate a top-level domain.
16
17
Parameters:
18
- tld_type (TLDType): Type of TLD (CCTLD, GTLD, etc.)
19
20
Returns:
21
str: TLD like ".com", ".org", ".uk"
22
"""
23
24
def tld(self) -> str:
25
"""
26
Alias for top_level_domain().
27
28
Returns:
29
str: Top-level domain
30
"""
31
```
32
33
### IP Address Generation
34
35
Generate IPv4 and IPv6 addresses with various purposes and formats.
36
37
```python { .api }
38
class Internet(BaseProvider):
39
def ip_v4(self) -> str:
40
"""
41
Generate a random IPv4 address.
42
43
Returns:
44
str: IPv4 address like "192.168.1.1"
45
"""
46
47
def ip_v4_object(self) -> ipaddress.IPv4Address:
48
"""
49
Generate an IPv4 address object.
50
51
Returns:
52
IPv4Address: IPv4 address object
53
"""
54
55
def ip_v4_with_port(self, port_range: PortRange = PortRange.ALL) -> str:
56
"""
57
Generate IPv4 address with port number.
58
59
Parameters:
60
- port_range (PortRange): Port range type (ALL, WELL_KNOWN, etc.)
61
62
Returns:
63
str: IPv4 with port like "192.168.1.1:8080"
64
"""
65
66
def ip_v6(self) -> str:
67
"""
68
Generate a random IPv6 address.
69
70
Returns:
71
str: IPv6 address like "2001:db8::1"
72
"""
73
74
def ip_v6_object(self) -> ipaddress.IPv6Address:
75
"""
76
Generate an IPv6 address object.
77
78
Returns:
79
IPv6Address: IPv6 address object
80
"""
81
82
def special_ip_v4(self, purpose: IPv4Purpose = None) -> str:
83
"""
84
Generate special-purpose IPv4 address.
85
86
Parameters:
87
- purpose (IPv4Purpose): Purpose type (PRIVATE, LOOPBACK, etc.)
88
89
Returns:
90
str: Special IPv4 address
91
"""
92
93
def special_ip_v4_object(self, purpose: IPv4Purpose = None) -> ipaddress.IPv4Address:
94
"""
95
Generate special-purpose IPv4 address object.
96
97
Parameters:
98
- purpose (IPv4Purpose): Purpose type
99
100
Returns:
101
IPv4Address: Special IPv4 address object
102
"""
103
```
104
105
### Network Infrastructure
106
107
Generate network-related identifiers and infrastructure data.
108
109
```python { .api }
110
class Internet(BaseProvider):
111
def mac_address(self) -> str:
112
"""
113
Generate a MAC address.
114
115
Returns:
116
str: MAC address like "00:1B:63:84:45:E6"
117
"""
118
119
def port(self, port_range: PortRange = PortRange.ALL) -> int:
120
"""
121
Generate a port number.
122
123
Parameters:
124
- port_range (PortRange): Port range (ALL, WELL_KNOWN, EPHEMERAL)
125
126
Returns:
127
int: Port number like 8080, 80, 443
128
"""
129
130
def asn(self) -> str:
131
"""
132
Generate an Autonomous System Number.
133
134
Returns:
135
str: ASN like "AS64512"
136
"""
137
138
def public_dns(self) -> str:
139
"""
140
Generate a public DNS server address.
141
142
Returns:
143
str: DNS server IP like "8.8.8.8"
144
"""
145
```
146
147
### URL and Web Data
148
149
Generate URLs, slugs, and web-related data structures.
150
151
```python { .api }
152
class Internet(BaseProvider):
153
def url(self, scheme: URLScheme = None) -> str:
154
"""
155
Generate a complete URL.
156
157
Parameters:
158
- scheme (URLScheme): URL scheme (HTTP, HTTPS, FTP, etc.)
159
160
Returns:
161
str: URL like "https://example.com/path"
162
"""
163
164
def slug(self, parts_count: int = None) -> str:
165
"""
166
Generate a URL slug.
167
168
Parameters:
169
- parts_count (int): Number of parts in slug
170
171
Returns:
172
str: Slug like "some-url-slug"
173
"""
174
175
def query_string(self, length: int = None) -> str:
176
"""
177
Generate a URL query string.
178
179
Parameters:
180
- length (int): Number of query parameters
181
182
Returns:
183
str: Query string like "param1=value1¶m2=value2"
184
"""
185
186
def query_parameters(self, length: int = None) -> dict:
187
"""
188
Generate query parameters as dictionary.
189
190
Parameters:
191
- length (int): Number of parameters
192
193
Returns:
194
dict: Parameters like {"param1": "value1", "param2": "value2"}
195
"""
196
```
197
198
### HTTP Protocol Data
199
200
Generate HTTP-related data including status codes, methods, and headers.
201
202
```python { .api }
203
class Internet(BaseProvider):
204
def http_status_code(self) -> int:
205
"""
206
Generate an HTTP status code.
207
208
Returns:
209
int: Status code like 200, 404, 500
210
"""
211
212
def http_status_message(self) -> str:
213
"""
214
Generate an HTTP status message.
215
216
Returns:
217
str: Status message like "OK", "Not Found"
218
"""
219
220
def http_method(self) -> str:
221
"""
222
Generate an HTTP method.
223
224
Returns:
225
str: Method like "GET", "POST", "PUT"
226
"""
227
228
def http_request_headers(self) -> dict:
229
"""
230
Generate HTTP request headers.
231
232
Returns:
233
dict: Headers dictionary
234
"""
235
236
def http_response_headers(self) -> dict:
237
"""
238
Generate HTTP response headers.
239
240
Returns:
241
dict: Headers dictionary
242
"""
243
244
def user_agent(self) -> str:
245
"""
246
Generate a user agent string.
247
248
Returns:
249
str: User agent like "Mozilla/5.0 (Windows NT 10.0; Win64; x64)..."
250
"""
251
```
252
253
### Content Types and Data Sources
254
255
Generate MIME types and database connection strings.
256
257
```python { .api }
258
class Internet(BaseProvider):
259
def content_type(self, mime_type: MimeType = None) -> str:
260
"""
261
Generate a content type/MIME type.
262
263
Parameters:
264
- mime_type (MimeType): MIME type category
265
266
Returns:
267
str: Content type like "application/json", "text/html"
268
"""
269
270
def dsn(self, dsn_type: DSNType = None, **kwargs) -> str:
271
"""
272
Generate a Data Source Name (database connection string).
273
274
Parameters:
275
- dsn_type (DSNType): Database type (POSTGRESQL, MYSQL, etc.)
276
- **kwargs: Additional connection parameters
277
278
Returns:
279
str: DSN like "postgresql://user:pass@localhost:5432/db"
280
"""
281
```
282
283
### Additional Web Resources
284
285
Generate additional internet resources including hostnames, URIs, paths, and stock images.
286
287
```python { .api }
288
class Internet(BaseProvider):
289
def hostname(self, tld_type: TLDType = None, subdomains: list[str] = None) -> str:
290
"""
291
Generate a hostname without scheme.
292
293
Parameters:
294
- tld_type (TLDType): Type of top-level domain
295
- subdomains (list[str]): List of subdomains to choose from
296
297
Returns:
298
str: Hostname like "api.example.com"
299
"""
300
301
def uri(
302
self,
303
scheme: URLScheme = URLScheme.HTTPS,
304
tld_type: TLDType = None,
305
subdomains: list[str] = None,
306
query_params_count: int = None
307
) -> str:
308
"""
309
Generate a complete URI with optional query parameters.
310
311
Parameters:
312
- scheme (URLScheme): URL scheme (HTTP, HTTPS, FTP, etc.)
313
- tld_type (TLDType): Type of top-level domain
314
- subdomains (list[str]): List of subdomains
315
- query_params_count (int): Number of query parameters
316
317
Returns:
318
str: Complete URI like "https://api.example.com/path?param=value"
319
"""
320
321
def path(self, *args, **kwargs) -> str:
322
"""
323
Generate a URL path.
324
325
Parameters:
326
- *args: Arguments passed to slug method
327
- **kwargs: Keyword arguments passed to slug method
328
329
Returns:
330
str: Path like "/some/url/path"
331
"""
332
333
@staticmethod
334
def stock_image_url(
335
width: int | str = 1920,
336
height: int | str = 1080,
337
keywords: list[str] = None
338
) -> str:
339
"""
340
Generate a stock image URL from Unsplash.
341
342
Parameters:
343
- width (int|str): Image width in pixels
344
- height (int|str): Image height in pixels
345
- keywords (list[str]): Search keywords for image
346
347
Returns:
348
str: Unsplash image URL
349
"""
350
```
351
352
## Usage Examples
353
354
### Basic Internet Data
355
356
```python
357
from mimesis import Internet
358
359
internet = Internet()
360
361
# Generate basic internet data
362
web_data = {
363
'ip': internet.ip_v4(),
364
'url': internet.url(),
365
'user_agent': internet.user_agent(),
366
'mac': internet.mac_address(),
367
'port': internet.port()
368
}
369
```
370
371
### IP Address Generation
372
373
```python
374
from mimesis import Internet
375
from mimesis.enums import PortRange, IPv4Purpose
376
377
internet = Internet()
378
379
# Different IP formats
380
ipv4_basic = internet.ip_v4() # "192.168.1.1"
381
ipv4_with_port = internet.ip_v4_with_port() # "192.168.1.1:8080"
382
ipv6_basic = internet.ip_v6() # "2001:db8::1"
383
384
# Special-purpose addresses
385
private_ip = internet.special_ip_v4(IPv4Purpose.PRIVATE) # "10.0.0.1"
386
loopback_ip = internet.special_ip_v4(IPv4Purpose.LOOPBACK) # "127.0.0.1"
387
388
# IP objects for advanced operations
389
ipv4_obj = internet.ip_v4_object()
390
network = ipv4_obj.network # Can access network methods
391
```
392
393
### Network Infrastructure
394
395
```python
396
from mimesis import Internet
397
from mimesis.enums import PortRange
398
399
internet = Internet()
400
401
# Network identifiers
402
mac = internet.mac_address() # "00:1B:63:84:45:E6"
403
dns = internet.public_dns() # "8.8.8.8"
404
asn = internet.asn() # "AS64512"
405
406
# Port numbers
407
well_known_port = internet.port(PortRange.WELL_KNOWN) # 80, 443, 22
408
ephemeral_port = internet.port(PortRange.EPHEMERAL) # 32768-65535
409
```
410
411
### HTTP and Web Data
412
413
```python
414
from mimesis import Internet
415
from mimesis.enums import URLScheme
416
417
internet = Internet()
418
419
# HTTP data
420
status_code = internet.http_status_code() # 200
421
status_msg = internet.http_status_message() # "OK"
422
method = internet.http_method() # "GET"
423
424
# URLs and slugs
425
https_url = internet.url(URLScheme.HTTPS) # "https://example.com/path"
426
ftp_url = internet.url(URLScheme.FTP) # "ftp://files.example.com/"
427
slug = internet.slug(parts_count=3) # "some-nice-slug"
428
429
# Query parameters
430
query_str = internet.query_string(length=3) # "a=1&b=2&c=3"
431
query_dict = internet.query_parameters(length=2) # {"param1": "value1", "param2": "value2"}
432
```
433
434
### Headers and Content Types
435
436
```python
437
from mimesis import Internet
438
from mimesis.enums import MimeType
439
440
internet = Internet()
441
442
# HTTP headers
443
request_headers = internet.http_request_headers()
444
# {'User-Agent': '...', 'Accept': '...', 'Accept-Language': '...'}
445
446
response_headers = internet.http_response_headers()
447
# {'Content-Type': '...', 'Server': '...', 'Content-Length': '...'}
448
449
# Content types
450
json_type = internet.content_type(MimeType.APPLICATION) # "application/json"
451
html_type = internet.content_type(MimeType.TEXT) # "text/html"
452
```
453
454
### Database Connection Strings
455
456
```python
457
from mimesis import Internet
458
from mimesis.enums import DSNType
459
460
internet = Internet()
461
462
# Different database types
463
postgres_dsn = internet.dsn(DSNType.POSTGRESQL)
464
# "postgresql://user:password@localhost:5432/database"
465
466
mysql_dsn = internet.dsn(DSNType.MYSQL)
467
# "mysql://user:password@localhost:3306/database"
468
469
# Custom DSN parameters
470
custom_dsn = internet.dsn(
471
DSNType.POSTGRESQL,
472
host="custom-host",
473
port=5433,
474
database="mydb"
475
)
476
```
477
478
### Complete Web Service Profile
479
480
```python
481
from mimesis import Internet
482
from mimesis.enums import URLScheme, PortRange
483
484
def generate_web_service_profile():
485
internet = Internet()
486
487
return {
488
'service': {
489
'domain': internet.domain_name(),
490
'url': internet.url(URLScheme.HTTPS),
491
'api_endpoint': f"{internet.url()}/api/v1",
492
},
493
'infrastructure': {
494
'ip_v4': internet.ip_v4(),
495
'ip_v6': internet.ip_v6(),
496
'port': internet.port(PortRange.WELL_KNOWN),
497
'mac_address': internet.mac_address(),
498
},
499
'monitoring': {
500
'dns_servers': [internet.public_dns() for _ in range(2)],
501
'asn': internet.asn(),
502
},
503
'http': {
504
'methods': [internet.http_method() for _ in range(3)],
505
'user_agents': [internet.user_agent() for _ in range(2)],
506
'content_types': [internet.content_type() for _ in range(3)],
507
},
508
'database': {
509
'dsn': internet.dsn(DSNType.POSTGRESQL),
510
'backup_dsn': internet.dsn(DSNType.MYSQL),
511
}
512
}
513
514
service_profile = generate_web_service_profile()
515
```