mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
IP::fromHexString handle ascii (#15504)
* IP::fromHexString handle ascii Some bad MIBs convert the hex to ascii on display. Attempt to decode that if the situation is detected. fixes #15501 * add ascii tests
This commit is contained in:
@@ -162,4 +162,15 @@ class StringHelpers
|
||||
{
|
||||
return $var === null || is_scalar($var) || (is_object($var) && method_exists($var, '__toString'));
|
||||
}
|
||||
|
||||
public static function asciiToHex(string $ascii, string $seperator = ''): string
|
||||
{
|
||||
$hex = [];
|
||||
$len = strlen($ascii);
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$hex[] = str_pad(strtoupper(dechex(ord($ascii[$i]))), 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
return implode($seperator, $hex);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user