Impacket ping6.py
Back to the category index / Back to the command index
Overview
Section titled “Overview”A small example that sends ICMPv6 Echo requests using Impacket’s IPv6 and ICMPv6 structures.
| Item | Details |
|---|---|
| Implementation | examples/ping6.py |
| Category | Packets / ICMP / capture |
| Size | 88 lines |
| Distribution | Installed as a script through scripts=examples/*.py in setup.py |
CLI and input
Section titled “CLI and input”This older sample does not handle -h. Check its usage message and top-level sys.argv handling.
python examples/ping6.py <src-ipv6> <dst-ipv6>src-ipv6: Source address used in the IPv6 header and ICMPv6 pseudo-header.dst-ipv6: Destination address for Echo Requests.- There are no additional options. With fewer than two arguments, it prints usage and exits with code 1.
Detailed processing flow
Section titled “Detailed processing flow”The script builds IPv6 addresses and an ICMPv6 Echo Request, sets a checksum that includes the pseudo-header, and sends it through a raw socket. It waits for a response, passes it to the IPv6/ICMPv6 decoder, and displays information and timing for the matching Echo Reply.
How it works
Section titled “How it works”The IPv6 version differs from the IPv4 version in what it passes to the kernel
and what goes into the checksum. It sets the source, destination, traffic class,
flow label, and hop limit on an IP6 object, then attaches an ICMPv6 Echo Request
as a child. The ICMPv6 checksum also includes the pseudo-header’s addresses, next header, and payload length.
The script sends only the ICMPv6 packet through a raw ICMPv6 socket and increments
the sequence number on each loop. It passes received bytes to ICMP6Decoder and
displays the Echo Reply type and echo sequence. The handling of received IPv6
extension headers and kernel-added headers depends on the OS’s raw socket behavior.
Neighbor Discovery, Path MTU, scope IDs, and link-local interface selection are outside this sample’s scope. Link-local addresses or hosts with multiple interfaces may therefore need additional parameters. Matching the identifier, sequence, and source address as well as the response type would improve accuracy across multiple probes.
Key implementation elements
Section titled “Key implementation elements”| Symbol | Location | Where to trace its responsibility |
|---|---|---|
| module-level entry | 1 | Parses arguments and runs at the top level |
Dependencies
Section titled “Dependencies”Within Impacket
Section titled “Within Impacket”| Module | Main names used |
|---|---|
impacket | ICMP6, IP6, ImpactDecoder, version |
Output, side effects, and required privileges
Section titled “Output, side effects, and required privileges”- Performs network probing or live packet capture. Check the send and receive scope, interface, filters, and handling of captured data.
- Raw socket or packet capture privileges may be required. Captured data may include third-party traffic.
Failure paths and cleanup
Section titled “Failure paths and cleanup”- Distinguish a missing input file, a damaged file, an incomplete read, and an unsupported format.
When changing the implementation
Section titled “When changing the implementation”The code depends on IP6, ICMP6, ImpactDecoder, and raw IPv6 sockets. Header and checksum rules differ from the IPv4 version. Even when sharing code, keep pseudo-header and extension-header handling separate.
Verification
Section titled “Verification”- Syntax:
python -m py_compile examples/ping6.py - CLI: Use a subprocess to check the usage message and exit code with no or too few arguments.
- No test specific to this command was found. Choose shared-module tests and, if needed, a run in an isolated environment.

