mercredi 3 février 2016

Test connection ip/port from imput form

I'm trying to make a form that test connection from the input IP and port & query port here is my code. It's not working dunno why. I took some parts from other codes and put them together, can you please help me with that?

Thank you.

<?php

$host =  $_POST["adress"];
$port =  $_POST["port"];
$query_port =  $_POST["query_port"];
$timeout = 2;

$tbegin = microtime(true); 

$fp = fsockopen($host, $port, $errno, $errstr, $timeout); 

$responding = 1;
if (!$fp) { $responding = 0; } 

$tend = microtime(true);

fclose($fp);

$mstime = ($tend - $tbegin) * 1000;
$mstime = round($mstime, 2);


?>


<div class="well">

    <div class="control-group">

                    <label class="control-label">
                <div class="row">
                    <div class="span4"><strong>Address <span class="text-error">*</span></strong></div>
                    <div class="span2"><strong>Port</strong></div>
                    <div class="span2"><strong>Query Port <span class="text-error">*</span></strong></div>              </div>
            </label>
            <div class="controls controls-row">
                <div class="pull-left"><input class="span4" type="text" id="address" name="address" placeholder="Type your server address..."><input class="span2" type="text" id="port" name="port" value="7777"><input class="span2" type="text" id="port_query" name="port_query" value="27015"></div>
                <div class="div-spacer pull-left">&nbsp;</div>
                <div id="address_notice" class="pull-left"></div>
            </div>
            <div class="clearfix"></div>

        <span class="help-block text-info"><i class="fa fa-info-circle"></i> <small>You can leave port empty if you use the default port</small></span>
        <span class="help-block text-info"><i class="fa fa-info-circle"></i> <small>You can leave query port empty if it's the same as server port</small></span>   </div>

    <a class="btn btn-small btn-info"  method="post">Check the connection <i class="fa fa-refresh"></i></a>

    <div style="height: 20px;"></div>

    <div id="connection_status" class="control-group" style="display: none;">
        <label class="control-label" for="connection_notice"><strong>Connection status</strong></label>
        <div id="connection_notice"><?php
        if($responding)
{
    echo "$host responded to requests on port $port in $mstime milliseconds!\n";
}
else
{
    echo "$host is not responding to requests on port $port!";
}?>
</div>
    </div>


</div>

Aucun commentaire:

Enregistrer un commentaire