When i want to get the cablemodem event log via SNMP, then i snmpwalk the 'mib-2.69.1.5.8.1' oid, but I had the problem because the SNMP store every event date in 'special' hex-string called DateAndTime format.
(In my case this is a 8 byte hex-string, like this: 07 B2 01 01 00 0A 14 00)
I would like to convert to human date, like this (1970.01.01. 00:10), so I wrote a PHP function:
function hex2date( $hexstring ) {
$date = "";
$p = unpack( "H*", substr( $hexstring, 0, 2 ) ); // year (2 byte)
$date .= hexdec( $p[1] ).".";
$p = unpack( "H*", substr( $hexstring, 2, 1 ) ); // month (1 byte)
$date .= sprintf( "%02s", hexdec( $p[1] ) ).".";
$p = unpack( "H*", substr( $hexstring, 3, 1) ); // day (1 byte)
$date .= sprintf( "%02s", hexdec( $p[1] ) ).". ";
$p = unpack( "H*", substr( $hexstring, 4, 1 ) ); // hour (1 byte)
$date .= sprintf( "%02s", hexdec( $p[1] ) ).":";
$p = unpack( "H*", substr( $hexstring, 5, 1 ) ); // minute (1 byte)
$date .= sprintf( "%02s", hexdec( $p[1] ) );
return ($date);
}
This is work, however for some reason I think that this is not the most elegant solution. Am I right?