gufo.ping.socket¶
PingSocket implementation.
Attributes:
| Name | Type | Description |
|---|---|---|
IPv4 |
IPv4 address family. |
|
IPv6 |
IPv6 address family. |
PingSocket
¶
Bases: object
Python API to Gufo Ping internals.
Python-side ICMP requests/reply dispatcher for the given address family. Wraps Rust socket implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
afi
|
int
|
Address Family. Either IPv4 or IPv6. |
IPv4
|
policy
|
SelectionPolicy
|
Probe selection policy. |
RAW
|
size
|
int
|
Set outgoing packet's size, including IP header. |
64
|
src_addr
|
str | None
|
Optional source address of outgoing packets. |
None
|
ttl
|
int | None
|
Set outgoing packet's TTL. Use OS defaults when empty. |
None
|
tos
|
int | None
|
Set DSCP/TOS field to outgoing packets. Use OS defaults when empty. |
None
|
timeout
|
float
|
Default timeout in seconds. |
1.0
|
send_buffer_size
|
int | None
|
Send buffer size. Use OS defaults when empty. |
None
|
recv_buffer_size
|
int | None
|
Receive buffer size. Use OS defaults when empty. |
None
|
coarse
|
bool
|
Use CLOCK_MONOTONIC_COARSE when set, fall back to CLOCK_MONOTONIC otherwise. |
False
|
__del__()
¶
Perform cleanup on delete.
clean_ip(addr)
¶
Normalize IP address to a stable form.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
str
|
IP address |
required |
Returns:
| Type | Description |
|---|---|
str
|
Normalized address |
ping(addr, size=None)
async
¶
Send ICMP echo request and await for result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
addr
|
str
|
Socket to ping. |
required |
size
|
int | None
|
Packet size in bytes, including IP header. |
None
|
SelectionPolicy
¶
Bases: IntEnum
Probe selection policy.
Allows automatical selection between implementations:
RAW- Raw sockets, requires root user (POSIX platforms) or CAP_NET_RAW capability (Linux).DGRAM- ICMP datagram socket (Linux only). Requiresnet.ipv4.ping_group_rangeto contain process' group.
Attributes:
| Name | Type | Description |
|---|---|---|
RAW |
Use RAW only. |
|
RAW_DGRAM |
Try RAW, fallback to DGRAM. |
|
DGRAM_RAW |
Try DGRAM, fallback to RAW. |
|
DGRAM |
Use DGRAM only. |