note 52966 added to function.fsockopen
| From: | richard dot lajaunie at cote-azur dot cci dot fr | Date: | Thu, 19 May 2005 07:10:09 +0000 |
| Subject: | note 52966 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89615@lists.php.net to get a copy of this message | ||
<?
/************************************************************
* Author: Richard Lajaunie
* Mail : richard.lajaunie@cote-azur.cci.fr
*
* subject : this script retreive all mac-addresses on all ports
* of a Cisco 3548 Switch by a telnet connection
*
* base on the script by: xbensemhoun at t-systems dot fr on the same page
**************************************************************/
if ( array_key_exists(1, $argv) ){
$cfgServer = $argv[1];
}else{
echo "ex: 'php test.php 10.0.0.0' \n";
exit;
}
$cfgPort = 23; //port, 22 if SSH
$cfgTimeOut = 10;
$usenet = fsockopen($cfgServer, $cfgPort, $errno, $errstr), $cfgTimeOut);
if(!$usenet){
echo "Connexion failed\n";
exit();
}else{
echo "Connected\n";
fputs ($usenet, "password\r\n");
fputs ($usenet, "en\r\n");
fputs ($usenet, "password\r\n");
fputs ($usenet, "sh mac-address-table\r\n");
fputs ($usenet, " "); // this space bar is this for long output
// this skip non essential text
$j = 0;
while ($j<16){
fgets($usenet, 128);
$j++;
}
stream_set_timeout($usenet, 2); // set the timeout for the fgets
$j = 0;
while (!feof($usenet)){
$ret = fgets($usenet, 128);
$ret = str_replace("\r", '', $ret);
$ret = str_replace("\n", "", $ret);
if (ereg("FastEthernet", $ret)){
echo "$ret \n";
}
if (ereg('--More--', $ret) ){
fputs ($usenet, " "); // for following page
}
$info = stream_get_meta_data($usenet);
if ($info['timed_out']) {
$j++;
}
if ($j >2){
fputs ($usenet, "lo");
break;
}
}
}
echo "End.\r\n";
?>
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52966
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52966&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52966&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52966&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52966&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52966&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52966&report=yes
Search -- http://master.php.net/manage/user-notes.php