note 79392 added to function.snmpget

From: Date: Sat, 24 Nov 2007 21:49:58 +0000
Subject: note 79392 added to function.snmpget
Groups: php.notes 
Request: Send a blank email to php-notes+get-132545@lists.php.net to get a copy of this message
Some SNMP agents return mac addresses as hex encoded ascii. e.g. '30:30:3a:31:37:3a:66:32:3a:39:62:3a:34:36:3a:30:65' Each octet represents 4 bits of the mac address. Some vendors may also encode the separators into the string. Heres a function to convert these strings back into plain hex. <?php $hexStr = '30:30:3a:31:37:3a:66:32:3a:39:62:3a:34:36:3a:30:65'; echo(str_replace(':','',hexStr2Ascii($hexStr))); function hexStr2Ascii($hexStr,$separator = ':'){ $hexStrArr = explode($separator,$hexStr); $asciiOut = null; foreach($hexStrArr as $octet){ $asciiOut .= chr(hexdec($octet)); } return $asciiOut; } ?> Outputs: '0017f29b460e' ---- Server IP: 194.145.210.4 Probable Submitter: 81.101.247.163 ---- Manual Page -- http://www.php.net/manual/en/function.snmpget.php Edit -- https://master.php.net/note/edit/79392 Del: integrated -- https://master.php.net/note/delete/79392/integrated Del: useless -- https://master.php.net/note/delete/79392/useless Del: bad code -- https://master.php.net/note/delete/79392/bad+code Del: spam -- https://master.php.net/note/delete/79392/spam Del: non-english -- https://master.php.net/note/delete/79392/non-english Del: in docs -- https://master.php.net/note/delete/79392/in+docs Del: other reasons-- https://master.php.net/note/delete/79392 Reject -- https://master.php.net/note/reject/79392 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132545) next »