I'm trying to write an PHP script that have to receive "DNS Push notification", RFC8490
I want to read the package for domainname, serial and i'dont know if other information exist also all other information.
The UDP packages are received without any problems with:
socket_recvfrom($socket, $udpData, 2048, 0, $remoteAddress, $remotePort);
Now i want to get the $updData to readable information, i have managed to get the domainname with this following script:
// Unpack the UDP data
$unpackedData = unpack('ntransaction_id/nflags/nqdcount/nancount/nnscount/narcount', $udpData);
// Extract the domain name from the UDP data
$pointer = 12; // Start position of the domain name in the UDP data
// Iterate over the labels in the domain name
while ($udpData[$pointer] !== "\x00") {
$labelLength = ord($udpData[$pointer]);
$label = substr($udpData, $pointer + 1, $labelLength);
$domainName .= $label . '.';
$pointer += $labelLength + 1;
}
$domainName = rtrim($domainName, '.');
Don't haven't found out how to get the serialnr of the DNS Push Notification, and if other i would like to get these to.
Can someone help me with this?
I'm searching everywhere for an solution, but till now not found any.
Serial should work with:
// Skip the domain name to reach the Answer section
$pointer += strlen(substr($udpData, $pointer)) + 5;
// Extract the serial number from the Answer section
$serialNumber = unpack('N', substr($udpData, $pointer + 20, 4))[1];
// Output the serial number
echo "Serial Number: " . $serialNumber . "\n";
But that isn't working doesn't get the right serialnumber from the notification.
Sample data:
$udpData = 'O5gkAAABAAEAAAAACnRlc3Rkb21laW4CbmwAAAYAAcAMAAYAAQAAAAAANARuczAxCGlzcGNsb3VkwBcGbm90aWZ5BmlzcHdlYsAXeJWZ4wAAqMAAABwgACTqAAAABwg=';
$udpData=base64_decode($udpData);