Hi,
Newbie here, but I'm trying!
So, I'm trying to read from a file which contains an IP address then, insert that IP address into my code which, then, opens a telnet session.
My code is working but when I read the IP address from the file, the PHP code inserts spaces between the numbers and dots in the IP address, so, instead of reading 192.168.1.1 I'm getting 1 9 2 . 1 6 8 . 1 . 1 which telnet wont recognise.
Here is the code:-
?php
require_once "php-telnet/PHPTelnet.php";
$telnet = new PHPTelnet();
$file = fopen("switchIPs2.txt", "r") or exit ("File not found!");
{
while (!feof($file))
{
$ip = fgets($file);
$result = $telnet->Connect($ip);
}
if ($result == 0) {
$telnet->DoCommand('password');
$telnet->DoCommand('en');
$telnet->DoCommand('password');
$telnet->DoCommand('copy running-config tftp:');
$telnet->DoCommand('192.168.1.2');
$telnet->DoCommand('');
$telnet->DoCommand('end');
$telnet->DoCommand('exit');
}
}
fclose($file);
?>
Please let me know if you require any further information to help me!
Your time is very much appreciated.
Kind regards,
Jamie.