how about this
[code] function get_cisco_phone_data($ip){ //start with the phones IP address $baseconfig = "http://".$ip; //open the site up $fp = fopen($baseconfig,"r"); if (!$fp) { echo "unable to open phone website..<br />\n"; }else { fputs($fp, "GET /".$ip."/ HTTP/1.0\r\n". "Host: \r\n". "User-Agent: ; \r\n\r\n"); $data = ''; while(!feof($fp)) { $data .= fgets($fp); } fclose($fp); } //convert the data to make a better match //start with the html tags so we can get those out of the way $converteddata = str_replace("</B></TD><td width=20></TD><TD><B>","",$data); $converteddata = str_replace("</B></TD></TR>","<end><br>",$converteddata); //now lets do something about the data that we want to get $converteddata = str_replace("<TR><TD><B> MAC Address","<start>MAC:1:",$converteddata); $converteddata = str_replace("<TR><TD><B> Host Name","Host:2:",$converteddata); $converteddata = str_replace("<TR><TD><B> Phone DN","Phone:3:",$converteddata); $converteddata = str_replace("<TR><TD><B> App Load ","AppL:4:",$converteddata); $converteddata = str_replace("<TR><TD><B> Boot Load ","BootL:5:",$converteddata); $converteddata = str_replace("<TR><TD><B> Version","Ver:6:",$converteddata); $converteddata = str_replace("<TR><TD><B> Hardware Revision","HardwareR:7:",$converteddata); $converteddata = str_replace("<TR><TD><B> Serial Number","Serial:8:",$converteddata); $converteddata = str_replace("<TR><TD><B> Model Number","Model:9:",$converteddata); $converteddata = str_replace("<TR><TD><B> Message Waiting","message:10:",$converteddata); //filter out the data and make a match $mac = preg_match('/(?P<name>\w+):1:(?P<val>\w+)/', $converteddata, $macout); $macaddress = $macout['val']; $host = preg_match('/(?P<name>\w+):2:(?P<val>\w+)/', $converteddata, $hostout); $hostname = $hostout['val']; $phone = preg_match('/(?P<name>\w+):3:(?P<val>\w+)/', $converteddata, $phoneout); $phonedn = $phoneout['val']; $serial = preg_match('/(?P<name>\w+):8:(?P<val>\w+)/', $converteddata, $serialout); $serial = $serialout['val']; $model = preg_match_all('/:9:([^<end>"]+)/i', $converteddata, $modelout); $model = $modelout['1']['0']; //now for the networking info from http://$ip/CGI/Java/Serviceability?adapter=device.statistics.configuration $networklocation = "http://".$ip."/CGI/Java/Serviceability?adapter=device.statistics.configuration"; $networkinfo = fopen($networklocation,"r"); if (!$networkinfo) { echo "unable to open phone website..<br />\n"; }else { fputs($networkinfo, "GET /".$ip."/ HTTP/1.0\r\n". "Host: \r\n". "User-Agent: ; \r\n\r\n"); $networkdata = ''; while(!feof($networkinfo)) { $networkdata .= fgets($networkinfo); } fclose($networkinfo); } //start with the html tags so we can get those out of the way $convertedndata = str_replace("</B></TD><td width=20></TD><TD><B>","",$networkdata); $convertedndata = str_replace("</B></TD></TR>","<end><br>",$convertedndata); //now lets do something about the data that we want to get $convertedndata = str_replace("<TR><TD><B> IP Address","IP:1:",$convertedndata); $convertedndata = str_replace("<TR><TD><B> Default Router 1","Router:2:",$convertedndata); //now get that info $ipaddress = preg_match_all('/:1:([^<end>"]+)/i', $convertedndata, $ipout); $ipfin = $ipout['1']['0']; $router = preg_match_all('/:2:([^<end>"]+)/i', $convertedndata, $routerout); $routerfin = $routerout['1']['0'];
//now to make the return of the data $enddata=array('macaddress'=>$macaddress,'host'=>$hostname,'phonedn'=>$phonedn,'serial'=>$serial,'model'=>$model,'ip'=>$ipfin,'router'=>$routerfin);
return $enddata; } [/code]
Usage [code] $phone = get_cisco_phone_data("xxx.xxx.xxx.xxx"); [/code]
Returns
[code] Array ( [macaddress] => 001AA2969767 [host] => SEP001AA2969767 [phonedn] => 2046 [serial] => FCH1051AK99 [model] => CP-7941G [ip] => xxx.xxx.xxx.xxx [router] => xxx.xxx.xxx.xxx ) [/code]
Todo Convert Mac address to add in the .'s Test on more than a 7941g system as I may need to rethink the muxing of the html for the matching
|