Jump to content
umarzuki

Periksa Port/servis Webserver Dengan Php

Recommended Posts

ni kod saja main2, maklumlah baru belajar sendiri

form_zps6fb25d5d.png

result_zpsf62af060.png
 

index.html

root@lamp:/var/www/tools/portcheck# cat index.html
<html>
<body>

<form action="check.php" method="post">
IP: <input type="text" name="IP"><br>
TCP Port: <input type="text" name="portNumber"><br>
<input type="submit">
</form>


<!--
Sumber: http://www.w3schools.com/php/php_form_complete.asp
http://www.ewhathow.com/2013/09/check-if-a-tcp-port-like-http-port-80-is-open-using-php/
-->

</body>
</html>

check.php

root@lamp:/var/www/tools/portcheck# cat check.php
<html>
<body>

Server IP: <?php echo $_POST["IP"]; ?><br>
Port: <?php echo $_POST["portNumber"]; ?>

<?php

$host = $_POST["IP"];
$port = $_POST["portNumber"];
$tbegin = microtime(true);

$fp = fsockopen($host, $port);

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

$tend = microtime(true);

fclose($fp);

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

if($responding)
{
    echo "<br />$host responded to requests on port $port in $mstime milliseconds!\n";
}
else
{
    echo "<br />$host is not responding to requests on port $port!";
}

?>
</body>
</html>

 

yang aku rasa perlu tambah

  • periksa input & implemen RBL/blacklist/whitelist untuk elak spammer
  • pilihan limit hanya untuk http & https

 

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...