PDA

View Full Version : PHP Based Ubiquiti Discovery Tool


alidamji
12-02-2009, 08:44 AM
Hi,
Below is a PHP (Socket based) Based discovery tool if someone is looking for one as i was:

<?php
/**
* @author Ali Damji <ali[a]damji.co.tz>
* @version 1.0
* @copyright (c) 2009, Ali Damji. You may copy, alter parts of this script freely.
* Based on http://85.89.32.5/lsdiscovery.c
*/

//$data1=sprintf("%c%c",0,0);
$data1=sprintf("%c%c%c%c",1,0,0,0);

# Listen on 2048
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1);
socket_bind($sock, '0.0.0.0', 2048);
socket_sendto($sock, $data1, strlen($data1), 0, '255.255.255.255', 10001); //Ubiquiti
//socket_sendto($sock, $data2, strlen($data2), 0, '255.255.255.255', 10001); //Ubiquiti
//socket_sendto($sock, $broadcast_string, strlen($broadcast_string), 0, '233.89.188.1', '10001'); //Ubiquiti
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 0);
while(true) {
$from='';$port='2048';
socket_recvfrom($sock, $buf, 512000, 0, $from, $port);
$result["ip"]=$from;
//$result["raw"]= bin2hex(substr($buf,strpos($buf,"aXS")));
$result["info"]= parse_result(bin2hex($buf));
print_r($result);
}


function parse_result($data) {
$result["mac"]=substr(str_replace("\r\n",":",chunk_split(substr($data,14,12),2)),0,-1);
$d=explode("\r\n",chunk_split($data,2));
$result["ip"]=hexdec($d[13]).".".hexdec($d[14]).".".hexdec($d[15]).".".hexdec($d[16]);
foreach ($d as $c=>$i) {
$val[$c]=pack("H*",$i);
$dec[$c]=hexdec($i);
}
foreach ($d as $c=>$i) {
if ($dec[$c]==11 && $dec[$c+1]==0) {
$length=$dec[$c+2]; $c+=2;
for($j=1;$j<=$length;$j++) $result["hostname"].=pack("H*",$d[$c+$j]);
}
if ($dec[$c]==12 && $dec[$c+1]==0) {
$length=$dec[$c+2]; $c+=2;
for($j=1;$j<=$length;$j++) $result["type"].=pack("H*",$d[$c+$j]);
}
if ($dec[$c]==3 && $dec[$c+1]==0) {
$length=$dec[$c+2]; $c+=2;
for($j=1;$j<=$length;$j++) $result["fw"].=pack("H*",$d[$c+$j]);
}
$t=pack("H*",$i);
//echo $i." - ".hexdec($i)." - ".$t."\n";
}
return $result;
}



?>

mousprabat
12-10-2009, 08:55 AM
Based discovery tool if someone is looking for one as i was:

CzechEnglishFrenchGermanItalianPolishPortugueseRussianSpanish
Translations supported by vB Enterprise Translator 3.5.4