Using IPv6 with the Ping Component
By default, the Ping component uses IPv4. To ping a host over IPv6, set the UseIPv6 configuration setting before calling the PingHost method:
| Value | Behavior |
|---|---|
| 0 (default) | IPv4 only. |
| 1 | IPv6 only. Host names are resolved to IPv6 addresses. |
| 2 | IPv6 with IPv4 fallback. When the host is an IP address, the component uses the address family of that address. |
Ping ping = new Ping();
ping.Config("UseIPv6=1");
ping.PingHost("2001:db8::1");
Console.WriteLine("Reply from " + ping.ResponseSource + " in " + ping.ResponseTime + " ms.");
When the same code must ping both IPv4 and IPv6 addresses, set UseIPv6 to 2, so that the address family is selected from the address that is passed to PingHost.
Link-Local Addresses
Link-local addresses (addresses that begin with fe80::) are only valid on a single network link, so the same address can exist on more than one interface. To ping a link-local address, append the zone ID (the index of the local interface to send the request on) to the address, separated by %:
ping.Config("UseIPv6=1");
ping.PingHost("fe80::cc64:9f01:5890:85e4%6");
On Windows, the interface index can be found using netsh interface ipv6 show interfaces (in the Idx column), or ipconfig, which shows the zone ID after the % in the link-local address of each interface.
To send the request from a specific local address, set the LocalHost property to that IPv6 address before calling PingHost.
Permissions
By default, the component sends ping requests using raw sockets, which on Windows require the application to run with administrator privileges. To ping without administrator privileges on Windows, set the UseIPHLPDLL configuration setting to true, so that the component uses the ping functions of the Windows IP Helper API (iphlpapi.dll), which supports both IPv4 and IPv6. Note that the UseICMPDLL configuration setting does not support IPv6.
ping.Config("UseIPHLPDLL=true");
ping.Config("UseIPv6=1");
ping.PingHost("2001:db8::1");
For more information, please see our Resolving Access Denied Errors with the ICMP Components entry.
Firewall Settings
The host being pinged must allow incoming ICMPv6 echo requests (type 128). Windows Firewall blocks these requests by default on many network profiles. To allow them on a Windows host, run the following command from an elevated command prompt:
netsh advfirewall firewall add rule name="Allow ICMPv6 Echo Request" protocol=icmpv6:128,any dir=in action=allow
The same rule can also be created in Windows Defender Firewall with Advanced Security, or by enabling the predefined File and Printer Sharing (Echo Request - ICMPv6-In) rule.
Note that older versions of Windows (such as Windows XP and Windows Server 2003) required the zone ID and the LocalHost property to be set for all IPv6 pings, and used the netsh firewall command, which has been replaced by netsh advfirewall.
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.