Hallo zusammen,
ich bin total am verzweifeln. Ich nutze für ein AutoIT Projekt die Net::Ping Klasse von Pear, was mit Ipv4 perfekt funktioniert. Ich wollte diese Klasse nun für IPv6 anpassen, wa sich aber leider nicht hinbekomme.
Das Problem ist das auslesen der IP Adresse aus dem Ping Result. Dazu gibt es in der Pear Klasse folgenden Part:
function _parseResultDetailTargetIp($upper)
{
// Grab the first IP addr we can find. Most ping flavors
// put the target IP on the first line, but some only list it
// in successful ping packet lines.
for ( $i=0; $i<count($upper); $i++ ) {
if ( preg_match('/(\d+\.\d+\.\d+\.\d+)/', $upper[$i], $matches) ) {
return( $matches[0] );
}
}
// no idea...
return( NULL );
}
Alles anzeigen
Ich habe nun versucht, dies folgendermassen anzupassen:
function _parseResultDetailTargetIp($upper)
{
// Grab the first IP addr we can find. Most ping flavors
// put the target IP on the first line, but some only list it
// in successful ping packet lines.
for ( $i=0; $i<count($upper); $i++ ) {
if ( preg_match('/(\d+\.\d+\.\d+\.\d+)/', $upper[$i], $matches) ) {
return( $matches[0] );
}
if ( preg_match('/^(((?=(?>.*?(::))(?!.+3)))3?|([dA-F]{1,4}(3|:(?!$)|$)|2))(?4){5}((?4){2}|(25[0-5]|(2[0-4]|1d|[1-9])?d)(.(?7)){3})z/i', $upper[$i], $matches) ) {
return( $matches[0] );
}
}
// no idea...
return( NULL );
}
Alles anzeigen
Die zweite "if (preg_match" Abfrage soll die IPv6 Adresse von der Pingabfrage auslesen und wiedergeben.
Das Pingergebnis sieht so aus:
PING google.de (2a00:1450:4013:c00::5e) 56 bytes of data.
56 bytes from google.de (2a00:1450:4013:c00::5e): icmp_seq=1 ttl=55 time=15.65 ms
56 bytes from google.de (2a00:1450:4013:c00::5e): icmp_seq=2 ttl=55 time=16.24 ms
--- google.de ping statistics ---
2 packets transmitted, 2 received, 0.00% packet loss, time 31.9ms
rtt min/avg/max/sdev = 15.650/15.945/16.240/0.417 ms
Hat jemand evtl. eine Ahnung, was im Regex der zweiten preg_match geändert werden, damit PHP die V6 Adresse findet und wiedergeben kann?