Current location: Hot Scripts Forums » Programming Languages » PHP » telnet router


telnet router

Reply
  #1 (permalink)  
Old 08-16-07, 11:36 AM
dieya dieya is offline
New Member
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
telnet router

hye..im new in PHP. for my final project, i will develop one system to configure router in telnet connection,like ping,traceroute and others.i have already found script to connect the router in telnet connection, but confused how to configure router by other command to configure the router..please, your help is very meaningful to me.and hope can share with me the guideline that can i review on it.
Reply With Quote
  #2 (permalink)  
Old 08-18-07, 09:31 PM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

Read up on PHP socket programming for starters:

http://www.php.net/sockets

Basic idea:

1) PHP connects to router via socket_create()
2) PHP sends username/password via socket_send() and gets the response via socket_read().
3) If we're connected ok, PHP sends the first command via socket_send()
4) PHP reads the router's response via socket_read()
5) If the response looks ok (ie. the router understood the command), we repeat steps 3 and 4 for each new command.
5) When we're done, PHP closes the connection via socket_close()

I'm sure between the scripts you have and the documentation on PHP's website, you'll have no problem accomplishing what you need.

Chris
__________________
Chris (aka Skeleton Man)
ProgrammingTalk's Perl/PHP Moderator !

Last edited by Skeleton Man; 08-18-07 at 09:33 PM.
Reply With Quote
  #3 (permalink)  
Old 08-28-07, 11:02 AM
dieya dieya is offline
New Member
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
i'm try using this script...and get the result.but the router command are running based on the command that write in the script.how can i make user insert the command for router configuration, example like show run, ping using button?

below are the script that be used for telnet to router
PHP Code:

 <?php 

            
//$value1=$_POST['text'];
            
$ip=$_POST['ip'];
            
$port=$_POST['host'];
    
            
$cfgServer $ip;  //IP of your router
            
$cfgPort    $port;                //port, 22 if SSH
            
$cfgTimeOut 10;
    
            
$usenet fsockopen($cfgServer$cfgPort, &$errno, &$errstr$cfgTimeOut);
    
                
?>  <textarea name="output" cols="80" rows="20" class="text1" id="output" readonly="readonly">
<?php
if(!$usenet)
        {
        echo 
"Connection failed\n";
          exit();
        }
            else
           {
//cisco command
           
echo "Connected\n";
       
fputs ($usenet"class\r\n");
          
fputs ($usenet"en\r\n");
       
fputs ($usenet"cisco\r\n");
     
// fputs ($usenet, "conf t\r\n");
     
fputs ($usenet"sh run\r\n");
     
fputs ($usenet" exit\r\n");
    
// while (!feof($usenet))
      //  {
        //echo " ".fgets($usenet, 128)."\n";
     //}
        
}?>  </textarea>
please..help me
Reply With Quote
  #4 (permalink)  
Old 08-28-07, 03:17 PM
Skeleton Man Skeleton Man is offline
Community Liaison
 
Join Date: Jun 2003
Location: Australia
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
If you mean "How I can I run a command when a user pushes a button on the page", then you would just use a normal HTML page and in PHP use $_POST to check if the button has been pushed:

PHP Code:

if ($_POST['button1']){
 
$command 'ping';
}else{
 
$command 'foo';
}

 
fputs ($usenet"$command\r\n"); 
If you want it interactive where it stays connected and the user can enter commands (instead of entering 1 command and disconnecting) then you're way out of your league to be honest (and should probably look into having someone write such a solution for you)
__________________
Chris (aka Skeleton Man)
ProgrammingTalk's Perl/PHP Moderator !
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
wireless signal drops to low/very low at 3/4 meters away from router crmpicco The Lounge 4 07-29-07 06:25 PM
cannot connect to Belkin WiFi Router from laptop network card crmpicco The Lounge 2 05-17-07 05:47 PM
Telnet luceroel Everything Java 0 12-12-06 04:24 PM
Telnet connection using fsockopen rafaxxes PHP 0 10-31-06 10:46 AM
perl script for telnet into a router.....???? vidya.damodaran Perl 1 06-21-05 11:41 PM


All times are GMT -5. The time now is 06:08 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.