Validating IP's without refreshing the page

0

I created a tool to help me test my proxy lists, it tests proxy by proxy and printa on the screen the result for min, but it is not only printing the results, What do I use to put the textarea which 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>functionenviar(){varbin=$("#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{}
?>
    
asked by anonymous 06.07.2017 / 09:08

1 answer

1

For your logic to work I had to make some changes. There were many mistakes that made the motive of the problem a mystery. But, finally, make the following changes:

File index.html

<html>
<head>
    <title> Teste de IP's </title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script><scriptsrc="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>

File 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 IP without refreshing the page. Another thing, put the comma-separated ip's in <textarea> to work

    
07.07.2017 / 20:48