Jump to content

problem with a php script


silently

Recommended Posts

The script is called php-ping and it is taken from theworldsend.net

I modified it so that instead of ping he will execute another command called scr

witch telnets to a switch and changes the vlan on an interface

 

the telnet script:

--------------------

#! /bin/bash

(

sleep 0.2;

echo admin;

sleep 0.2;

echo parola;

echo interface ethernet $2;

echo port access vlan 222;

echo quit;

echo save;

echo y;

sleep 5;

) | telnet $1

------------------------------

ex  scr  $1(ip) $2(interface)

ex: scr 10.10.10.1 0/2

telnets to 10.10.10.1 and chamges the vlan on the interface 0/2

 

The php script

---------------------------------------------

<html>

<?php

$max_count = 10; //maximum count for ping command

$unix      =  1; //set this to 1 if you are on a *unix system     

$windows  =  0; //set this to 1 if you are on a windows system

// -------------------------

// nothing more to be done.

// -------------------------

//globals on or off ?

$register_globals = (bool) ini_get('register_gobals');

$system = ini_get('system');

$unix = (bool) $unix;

$win  = (bool)  $windows;

//

If ($register_globals)

{

  $ip = getenv(REMOTE_ADDR);

  $self = $PHP_SELF;

}

else

{

  $submit = $_GET['submit'];

  $count  = $_GET['count'];

  $host  = $_GET['host'];

  $ip    = $_SERVER['REMOTE_ADDR'];

  $self  = $_SERVER['PHP_SELF'];

};

// form submitted ?

If ($submit == "Ping!")

{

  // over count ?

  If ($count > $max_count)

  {

      echo 'Maximum for count is: '.$max_count;

      echo '<a href="'.$self.'">Back</a>';

  }

  else

  {

      // replace bad chars

      $host= preg_replace ("/[^A-Za-z0-9.-]/","",$host);

      $count= preg_replace ("/[^0-9]/","",$count);

      echo '<body bgcolor="#FFFFFF" text="#000000"></body>';

      echo("Ping Output:<br>");

      echo '<pre>';         

      //check target IP or domain

      if ($unix)

      {

        system ("ping -c$count -w$count $host");

              }

      else

      {

        system("ping -n $count $host");

      }

      echo '</pre>';

    }

}

else

{

    echo '<body bgcolor="#FFFFFF" text="#000000"></body>';

    echo '<p><font size="2">Your IP is: '.$ip.'</font></p>';

    echo '<form methode="post" action="'.$self.'">';

    echo '  Enter IP or Host <input type="text" name="host" value="'.$ip.'"></input>';

    echo '  Enter Count <input type="text" name="count" size="2" value="4"></input>';

    echo '  <input type="submit" name="submit" value="Ping!"></input>';

    echo '</form>';

    echo '<br><b>'.$system.'</b>';

    echo '</body></html>';

}

?>

------------------------------------------------------------

Instead of ping i changed to scr command

The problem is that i don't know how to modifiy it so that it reads the interface ($2)

 

Thank you

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.