Jump to content

jhancock

New Members
  • Posts

    8
  • Joined

  • Last visited

jhancock's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. fixed, comer in the wrong place. Thanks for all your help. J.
  2. Fixed, comer in the wrong place! Thanks for all your help. J.
  3. By the way this is the code as it stands at the moment. <?php require_once "php-telnet/PHPTelnet.php"; $telnet = new PHPTelnet(); $lines = file("switchIPs2a.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); //reads each line into array foreach($lines as $ip) { $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.1'); $telnet->DoCommand(''); $telnet->DoCommand('end'); $telnet->DoCommand('exit'); } echo 'Sleeping for 10 seconds'; sleep(10); ?>
  4. Once again thank you for your reply. The code is running but its only inserting the last IP address which is contained in the file switchIPs2.txt. So, if I have 3 IP address like this:- 192.168.1.1 192.168.1.2 192.168.1.3 The code is only inserting 192.168.1.3? Sorry to be a pain. J.
  5. Thanks AbraCadaver. So would my code look like this? <?php require_once "php-telnet/PHPTelnet.php"; $telnet = new PHPTelnet(); $file = fopen("switchIPs2a.txt", "r") or exit ("File not found!"); { while (!feof($file)) { $ip = fgets($file); $lines = file("switchIPs2.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); //reads each line into array foreach($lines as $ip) { $result = $telnet->Connect($ip); } } if ($result == 0) { $telnet->DoCommand('K1n94+'); $telnet->DoCommand('en'); $telnet->DoCommand('K1n94+'); $telnet->DoCommand('copy running-config tftp:'); $telnet->DoCommand('192.168.110.237'); $telnet->DoCommand(''); $telnet->DoCommand('end'); $telnet->DoCommand('exit'); } } fclose($file); echo 'Sleeping for 10 seconds'; sleep(10); ?>
  6. Sorry, one further question, It oly seems to read the first line of the file. Can you help me amend my code to that it reads down the file please? Ja.
  7. Sorry the question was how do I take out the spaces, I thought that would be obvious. I have fixed the problem by saving the text file as ANSI rather than the default of Unicode. J.
  8. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.