N
N
Nicholas2015-10-02 05:10:26
Browsers
Nicholas, 2015-10-02 05:10:26

Ping from browser?

Are there options to ping from the browser?
Why:
There are two servers, one in Moscow and the other in Vladivostok, and you need to determine the closest one to the client (browser) through javascript

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Krymtsev, 2015-10-02
@krimtsev

If purely from the browser, then the answer will be given with a delay. To make it online, as in the command line, then google it better on Looking Glass, but you need iron there.

<?php
/*
 * credits to:
 * c00kiemon5ter for various suggestions
 * HdkiLLeR(vpk) for security tips
 */
?>
<html xmlns="http://www.w3.org/1999/xhtml" dir="" lang="ru" xml:lang="ru">
<head>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
  <link rel="icon" type="image/png" href="favicon.png" />
    <link rel="shortcut icon" href="favicon.ico" />
  <link rel="stylesheet" type="text/css" href="./css/style.css">
<title>Network Tools</title>
</head>

<body>
<div class="wrap">
<h1>LDS Network Tools</h1>
<center>
<form name="input" action="index.php" method="get">
<select name="servise">
<option value="ping">ping </option>
<option value="traceroute">traceroute</option>
<option value="nslookup">nslookup</option>
</select>
IP:
<input type="text" name="address" />
<input type="submit" name ="submit" value="Отправить" />
</form></center><br />
<?php
if(isset($_GET['submit']))
{
  // use of escapeshellcmd - must be enabled
  // http://php.net/manual/en/function.escapeshellcmd.php
  // escapes #&;`|*?~<>^()[]{}$\, \x0A and \xFF. ' and " 
  // are escaped only if they are not paired. 
  $servise = trim($_GET['servise']);
  $address = trim($_GET['address']);
    if( 
           (strpos($address,'/')>0)
        || (strpos($address,'/')===0) )
  {
    echo "Не шути так!";
    exit();
  }
  if($servise=="ping")
  {
    exec("ping '".escapeshellcmd($address)."' -c 4",$results); exec("ping '".escapeshellcmd($address)."' -c 4 -s 14500",$results2);
  }
  if($servise=="traceroute")
  {
    exec("traceroute '".escapeshellcmd($address)."'",$results3);
  }
  if($servise=="nslookup")
  {
    exec("nslookup '".escapeshellcmd($address)."'",$results3);
  }
  foreach($results3 as $result3)
  {
    echo $result3;
    echo "<br />";
  }
  if($results == null)
  {
    echo "<center><br />¯\_(ツ)_/¯</center>";
  }
  echo "<br />";
}
?>
<div class="col1"><h4>Обычным пингом</h4>
  <div data-layzr="media/source" class="block1">
    <?php 
    foreach($results as $result){
      echo $result;
      echo "<br />";
    }
    ?>
  </div></div>
  
    <div class="col1"><h4>Под нагрузкой</h4>
  <div data-layzr="media/source" class="block1">
  <?php 
  foreach($results2 as $result2){
    echo $result2;
    echo "<br />";
  }
  ?>
  </div></div>
</div>
</body>
</html>

body { background: url(../img/bg.jpg) no-repeat center top; background-color: #024162; font-family: Arial, Helvetica, sans-serif;}

.wrap { width:1000px; margin: 35 auto; background:#fff; padding: 20px 20px 20px 20px;}
.col1 { width:49%; float:left; margin-left: 7px; background:#CCC; padding-top: 10px;}
.block1 { margin: 5px 5px 5px 5px; width: 94%; padding: 8px; border:1px solid #999; background:#FFF;}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question