IP validation without updating the page

Asked

Viewed 94 times

0

I created a tool to help me test my proxy lists, it tests proxy and printa on the screen the result for min, but it is not printing only the result but also this printing the textarea what use to put the proxys that are tested how can I fix this ?

<html>

<head>
<title> testar ips </title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script>
      function enviar(){
        var bin = $("#bin_id").val();
        var linhaenviar = bin.split("\n");
        var index = 0;
        linhaenviar.forEach(function(value){

          setTimeout(

            function(){
              $.ajax({
                url: 'index.php',
                type: 'POST',
                dataType: 'html',
                data: "bin=" + value,
                success: function(resultado){
                  document.write(resultado + "<br>");
              }
            })

          }, 10 * index);

        index = index + 3;

        })
      }
  </script>

</head>
<body>
<center>
<textarea name="ip" id="ip_id" rows="10" cols="40">
</textarea>
<br>
<input type="button" value="testar ips" onclick="enviar();"></input>
</center>
</body>
</html>


<?php


error_reporting(0);

 if ($_POST['ip']) {
    $bin = substr($_POST['ip'], 0, 90);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "fonte dps testes");
            curl_setopt($ch, CURLOPT_HEADER, 1);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt( $ch, CURLOPT_POSTFIELDS, "input_proxy=$ip" );
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            $s = curl_exec($ch);
            $pop = preg_match( '/<p>(.*)<\/p>/si' , $s , $match);


$vdd = ' ';

if($pop >= "1") 

{ $vdd = "<b><font color='red'>#DIE_IPS </font></b>"; } 

else { $vdd = "<b><font color='green'>#LIVE_IPS </font></b>"; }


 $tudo = " [".$ip." ".$vdd."] ";


 echo "<br><br><center>".$vdd." ".$ip."</center>";
   }else{}
?>
  • You could put an example of text that you put on <textarea>?

  • 192.168.45.1 and a tool to test proxys

1 answer

1


For your logic to work, I had to make some changes. I had many mistakes that make the reason for the problem a mystery. But finally make the following changes:

Filing cabinet index.html

<html>
<head>
    <title> Teste de IP's </title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
    <script src="http://malsup.github.com/jquery.form.js"></script>
    <style>
        .red {
            color: brown;
        }
        .green{
            color: darkgreen;
        }
    </style>
</head>
<body>
    <form id="valida_ip" action="validaIP.php" method="post">
        <textarea name="ip" rows="10" cols="40"></textarea>
        <button type="submit">Enviar IP's</button>
    </form>
    <div id="reultados"></div>
    <script>
        $(document).ready(function () {
            $('#valida_ip').ajaxForm(function(data) {
                data = JSON.parse(data);
                $('#reultados').html('');
                if(data.ip != '') {
                    data.forEach(function (ip) {
                        $('#reultados').append('<li class="'+ip.class+'">'+ip.ip+'</li>');
                    });
                } else {
                    $('#reultados').append('<li class="'+data.class+'"> Erro ao ler informações no Textarea</li>');
                }
            });
        });
    </script>
</body>
</html>

Filing cabinet validaIP.php

<?php
if ($_POST['ip']) {
    $response = [];
    //gera um array de ip's, separando a string por virgula
    $ips = explode(',', $_POST['ip']);
    //$bin = substr($_POST['ip'], 0, 90);

    foreach ($ips as $ip) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "fonte dps testes");
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "input_proxy=$ip");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        $s = curl_exec($ch);
        $pop = preg_match('/<p>(.*)<\/p>/si', $s, $match);

        if ($pop) {
            array_push($response, [
                'class' => 'red',
                'ip' => '[ ' . $ip . ' #DIE_IPS ]'
            ]);
        } else {
            array_push($response, [
                'class' => 'green',
                'ip' => '[ ' . $ip . ' - #LIVE_IPS ]'
            ]);
        }
    }

    echo json_encode($response);
}else{
    echo json_encode([
            'class' => 'red',
            'ip' => ''
        ]);
}

Note: This example validates the IP without updating the page. Otherwise, put the comma separated ip’s in the <textarea> to work

  • thanks however the problem I face is to give looping code type: php will test the proxy of the first line and then print the result, will test the of the second and will print the result under the first and so will print one below the other testing all lines until there is no more and without updating the page all in the same index 1 result below the other

  • I changed the answer according to your need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.