Skip to content

Commit 2d3ceea

Browse files
committed
Rewrite the documentation: utilities
1 parent d9c2591 commit 2d3ceea

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

docs/5-utilities.md

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Utilities
2+
3+
### resolve
4+
5+
Resolve a hostname or FQDN to an IP address. Depending on the name specified in parameters, several IP addresses may be returned.
6+
7+
This function relies on the DNS name server configured on your operating system.
8+
9+
```python
10+
resolve(name, family=None)
11+
```
12+
13+
#### Parameters
14+
15+
- `name`
16+
17+
A hostname or a Fully Qualified Domain Name (FQDN).
18+
19+
- Type: `str`
20+
21+
- `family`
22+
23+
The address family. Can be set to `4` for IPv4 or `6` for IPv6 addresses. By default, this function searches for IPv4 addresses first for compatibility reasons (A DNS lookup) before searching for IPv6 addresses (AAAA DNS lookup).
24+
25+
- Type: `int`
26+
- Default: `None`
27+
28+
#### Return value
29+
30+
- A list of IP addresses corresponding to the name passed as a parameter.
31+
32+
#### Exceptions
33+
34+
- [`NameLookupError`]
35+
36+
If you pass a hostname or FQDN in parameters and it does not exist or cannot be resolved.
37+
38+
#### Example
39+
40+
```python
41+
>>> from icmplib import resolve
42+
43+
>>> resolve('one.one.one.one')
44+
['1.0.0.1', '1.1.1.1']
45+
46+
>>> resolve('localhost')
47+
['127.0.0.1']
48+
49+
>>> resolve('ipv6.google.com')
50+
['2a00:1450:4007:813::200e']
51+
```
52+
53+
<br>
54+
55+
### async_resolve
56+
57+
Resolve a hostname or FQDN to an IP address. Depending on the name specified in parameters, several IP addresses may be returned.
58+
59+
This function relies on the DNS name server configured on your operating system.
60+
61+
*This function is non-blocking.*
62+
63+
```python
64+
async_resolve(name, family=None)
65+
```
66+
67+
#### Parameters, return value and exceptions
68+
69+
The same parameters, return values and exceptions as for the [`resolve`](#resolve) function.
70+
71+
#### Example
72+
73+
```python
74+
>>> import asyncio
75+
>>> from icmplib import async_resolve
76+
77+
>>> asyncio.run(async_resolve('one.one.one.one'))
78+
['1.0.0.1', '1.1.1.1']
79+
80+
>>> asyncio.run(async_resolve('localhost'))
81+
['127.0.0.1']
82+
83+
>>> asyncio.run(async_resolve('ipv6.google.com'))
84+
['2a00:1450:4007:813::200e']
85+
```
86+
87+
<br>
88+
89+
### is_hostname
90+
91+
Indicate whether the specified name is a hostname or an FQDN.
92+
93+
```python
94+
is_hostname(address)
95+
```
96+
97+
#### Example
98+
99+
```python
100+
>>> from icmplib import is_hostname
101+
102+
>>> is_hostname('one.one.one.one')
103+
True
104+
105+
>>> is_hostname('localhost')
106+
True
107+
108+
>>> is_hostname('127.0.0.1')
109+
False
110+
111+
>>> is_hostname('2a00:1450:4007:813::200e')
112+
False
113+
```
114+
115+
<br>
116+
117+
### is_ipv4_address
118+
119+
Indicate whether the specified address is an IPv4 address.
120+
121+
This function does not perform a strict checking. Its does not check if each byte of the IP address is within the allowed range.
122+
123+
This function has been designed to be fast.
124+
125+
```python
126+
is_ipv4_address(address)
127+
```
128+
129+
#### Example
130+
131+
```python
132+
>>> from icmplib import is_ipv4_address
133+
134+
>>> is_ipv4_address('one.one.one.one')
135+
False
136+
137+
>>> is_ipv4_address('localhost')
138+
False
139+
140+
>>> is_ipv4_address('127.0.0.1')
141+
True
142+
143+
>>> is_ipv4_address('2a00:1450:4007:813::200e')
144+
False
145+
```
146+
147+
<br>
148+
149+
### is_ipv6_address
150+
151+
Indicate whether the specified address is an IPv4 address.
152+
153+
This function does not perform a strict checking. Its does not check if each byte of the IP address is within the allowed range.
154+
155+
This function has been designed to be fast.
156+
157+
```python
158+
is_ipv6_address(address)
159+
```
160+
161+
#### Example
162+
163+
```python
164+
>>> from icmplib import is_ipv6_address
165+
166+
>>> is_ipv6_address('one.one.one.one')
167+
False
168+
169+
>>> is_ipv6_address('localhost')
170+
False
171+
172+
>>> is_ipv6_address('127.0.0.1')
173+
False
174+
175+
>>> is_ipv6_address('2a00:1450:4007:813::200e')
176+
True
177+
```
178+
179+
[`NameLookupError`]: 4-exceptions.md#NameLookupError

0 commit comments

Comments
 (0)