lancom config via PHP abrufen?

Forum zu aktuellen Geräten der LANCOM Router/Gateway Serie

Moderator: Lancom-Systems Moderatoren

Antworten
aag
Beiträge: 60
Registriert: 08 Jan 2012, 14:21

lancom config via PHP abrufen?

Beitrag von aag »

Es geht sicher - aber ich weiss nicht wie! Ich würde gerne einige Tabellen (z.B. die Masquerading-Tabelle) von meinem Router via PHP abrufen, zwecks Weiterverarbeitung.

Kann mir jemand ein Tipp geben, wie dieses Vorhaben in etwa angegangen werden kann? Ich brauche nur einen Anschub - die Details werde ich schon selber ausarbeiten!

Danke im Voraus
AAG
aag
Beiträge: 60
Registriert: 08 Jan 2012, 14:21

Beitrag von aag »

Habe letztlich selber herausgefunden. Diese Funktion gibt ein Array heraus ($DhcpArray), welches die DHCP-Tabelle eines Lancom-Routers enthält.

Es müssen folgende Parameters gesetzt werden:
$router_ip = 'string';
$username = 'string';
$password = 'string';


[PHP]
<?php

$port = 23;
$timeout = 10;
$router_ip = '';
$username = '';
$password = '';

$connection = fsockopen($router_ip, $port, $errno, $errstr, $timeout);

if(!$connection){
echo "Connection failed\n";
exit();
} else {
echo "Connected\n";
fputs($connection, "$username\r\n");
fputs($connection, "$password\r\n");
fputs($connection, "cd setup/dhcp/dhcp-table \r\n");
fputs($connection, "dir \r\n");
fputs($connection, " ");

$j = 0;
while ($j < 16) {
fgets($connection);
$j++;
}
stream_set_timeout($connection, 2);
$timeoutCount = 0;
$content ='';
$DhcpArray = '';
(int) $index =0;
while (!feof($connection)){

$content = fgets($connection);
$content = str_replace("\r", '', $content);
$content = str_replace("\n", "", $content);
if (isValidIp(explode(' ', $content)[0]))
{ $index +=1;
$DhcpArray[$index]= $content;}

# If the router say "press space for more", send space char:
if (preg_match('/MORE/', $content) ){ // IF current line contain --More-- expression,
fputs ($connection, " "); // sending space char for next part of output.
} # The "more" controlling part complated.

$info = stream_get_meta_data($connection);
if ($info['timed_out']) { // If timeout of connection info has got a value, the router not returning a output.
$timeoutCount++; // We want to count, how many times repeating.
}
if ($timeoutCount >2){ // If repeating more than 2 times,
break; // the connection terminating..
}
}
$content = substr($content,410);
print "content: ".chr(13).$content."\n";
print_r ($DhcpArray);



$myFile = "C:\IP-Symcon\webfront\user\images\LancomDhcp.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $content;
fwrite($fh, $stringData);
fclose($fh);

}
echo "End.\r\n";

function isValidIp($ip)
{/* PCRE Pattern written by Junaid Atari */
return !preg_match ( '/^([1-9]\d|1\d{0,2}|2[0-5]{2})\.('.
'(0|1?\d{0,2}|2[0-5]{2})\.){2}(0|1?'.
'\d{0,2}|2[0-5]{2})(\:\d{2,4})?$/',
(string) $ip )
? false
: true;
}

?>
[/PHP]
Antworten