Skip to content

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 4 or 6

IPv4
size int

Set outgoing packet's size, including IP header.

64
src_addr Optional[str]

Optional source address of outgoing packets.

None
ttl Optional[int]

Set outgoing packet's TTL. Use OS defaults when empty.

None
tos Optional[int]

Set DSCP/TOS field to outgoing packets. Use OS defaults when empty.

None
timeout float

Default timeout in seconds.

1.0
send_buffer_size Optional[int]

Send buffer size. Use OS defaults when empty.

None
recv_buffer_size Optional[int]

Receive buffer size. Use OS defaults when empty.

None
coarse bool

Use CLOCK_MONOTONIC_COARSE when set, fall back to CLOCK_MONOTONIC otherwise.

False
accelerated bool

Enable platform-dependend accelerated socket processing.

True

__del__()

Perform cleanup on delete.

  • Cancel expiration task.
  • Remove socket reader.

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, request_id=0, seq=0) async

Send ICMP echo request and await for result.

Parameters:

Name Type Description Default
addr str

Socket to ping.

required
size Optional[int]

Packet size in bytes, including IP header.

None
request_id int

ICMP request id.

0
seq int

ICMP sequental number.

0