Skip to content

Instantly share code, notes, and snippets.

@saudiqbal
Created August 24, 2020 22:23
Show Gist options
  • Save saudiqbal/dcd1e606853adeb5cecc9cc5b2177c29 to your computer and use it in GitHub Desktop.
Save saudiqbal/dcd1e606853adeb5cecc9cc5b2177c29 to your computer and use it in GitHub Desktop.
PHP Port Checker
<!DOCTYPE html>
<html>
<head>
<title>Port Scanner</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="user-scalable=yes, initial-scale=1, width=device-width" />
<style>
body {
background: #f4f4f4;
width:100%;
top:0;
left:0;
margin:0;
padding:0;
text-align: center;
}
.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}
.middle {
display: table-cell;
vertical-align: middle;
}
.inner {
margin-left: auto;
margin-right: auto;
width: 100%;
}
hr.hr-style{
border:0;
height:1px;
background-image:-webkit-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.75),rgba(0,0,0,0));
background-image:-moz-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.75),rgba(0,0,0,0));
background-image:-ms-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.75),rgba(0,0,0,0));
background-image:-o-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.75),rgba(0,0,0,0));
margin:0px;
}
.new_lifted {
border-radius:2px;
position:relative;
padding:1em;
background:#fcfcfc;
box-shadow: 0px 0px 1px 1px rgba(0,0,0,0.2);
-o-box-shadow: 0px 0px 1px 1px rgba(0,0,0,0.2);
-moz-box-shadow: 0px 0px 1px 1px rgba(0,0,0,0.2);
display: inline-block;
min-width: 325px;
}
.new_lifted:before, .new_lifted:after {
content: "";
position: absolute;
z-index: -1;
-ms-transform: skew(-3deg,-2deg);
-webkit-transform: skew(-3deg,-2deg);
-o-transform: skew(-3deg,-2deg);
-moz-transform: skew(-3deg,-2deg);
bottom: 14px;
box-shadow: 0 15px 5px rgba(0, 0, 0, 0.3);
height: 50px;
left: 1px;
width: 50%;
}
.new_lifted:after {
-ms-transform: skew(3deg,2deg);
-webkit-transform: skew(3deg,2deg);
-o-transform: skew(3deg,2deg);
-moz-transform: skew(3deg,2deg);
left: auto;
right: 1px;
}
ul,li {
list-style-type: none;
list-style-position:inside;
margin:0;
padding:0;
}
form > div {
clear: both;
overflow: hidden;
padding: 1px;
margin: 0px;
}
form > div > fieldset > div > div {
margin: 0 0 5px 0;
}
form > div > label,
legend {
width: 30%;
float: left;
padding-right: 0px;
text-align: right;
}
form > div > div,
form > div > fieldset > div {
width: 70%;
float: right;
}
form > div > fieldset label {
font-size: 100%;
}
fieldset {
border: 0;
padding: 0;
}
input[type=text],
input[type=email],
input[type=url],
input[type=number],
input[type=password],
textarea {
width: 95%;
border-top: 1px solid #ccc;
border-left: 1px solid #ccc;
border-right: 1px solid #eee;
border-bottom: 1px solid #eee;
}
input[type=text],
input[type=email],
input[type=url],
input[type=number],
input[type=password] {
width: 95%;
}
input[type=text]:focus,
input[type=email]:focus,
input[type=url]:focus,
input[type=number]:focus,
input[type=password]:focus,
textarea:focus {
outline: 0;
border-color: #4697e4;
}
/* ====== BEGIN CELL PHONE CSS ====== */
@media screen and (max-width: 640px) {
/* Contact Form */
form > div {
margin: 0 0 15px 0;
}
form > div > label,
legend {
width: 100%;
float: none;
margin: 0 0 5px 0;
}
form > div > div,
form > div > fieldset > div {
width: 100%;
float: none;
}
input[type=text],
input[type=email],
input[type=url],
input[type=number],
input[type=password],
textarea,
select {
width: 95%;
}
.new_lifted {
width:90%;
height: auto;
}
}
</style>
</head>
<body>
<div class="outer">
<div class="middle">
<div class="inner">
<div class="new_lifted">
<?php
$starttime = microtime(true);
/* Port Checking PHP Script
Created by Jonesy44
Released: 30 November, 2008 */
//echo '<title>Port Availability Checker';
//Please leave the next line :)
//echo ', Writen by Jonesy44';
//echo '</title>';
$addr = $_SERVER["REMOTE_ADDR"];
$port = "80";
if (isset($_GET["addr"])) {
$addr = $_GET["addr"];
}
if (!isset($addr)) {
$addr = null;
}
if (isset($_GET["port"])) {
$port = $_GET["port"];
}
if (!isset($port)) {
$port = null;
}
if (isset($_GET["port2"])) {
$port2 = $_GET["port2"];
}
if (!isset($port2)) {
$port2 = null;
}
echo '<form action="' .$_SERVER["PHP_SELF"]. '" method="get">
<div style="width:300px;background:#fcfcfc;padding:10px;font-family:arial;">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td colspan="2" style="font-size:12px;">Please enter the Address/IP and port of the website or IP address you wish to test (enter the second IP if you want so scan to that port range)</td>
</tr>
<tr>
<td width="30%" style="font-size:12px;">Address/IP</td>
<td width="80%"><input type="text" name="addr" value="' .$addr. '"></td>
</tr>
<tr>
<td width="30%" style="font-size:12px;">Port</td>
<td width="80%"><input type="text" name="port" value="' .$port. '"></td>
</tr>
<tr>
<td width="30%" style="font-size:12px;">-</td>
<td width="80%"><input type="text" name="port2" value="' .$port2. '"></td>
</tr>
<td width="30%">&nbsp;</td>
<td width="80%"><input type="submit" value="Check/Scan Port(s)"></td>
</tr>
</table>
</div>
</form>
';
$p_open = '';
$p_1 = false;
if (isset($_GET["addr"])) {
if ($_GET["port"] && !$_GET["port2"]) {
$fp = @fsockopen($addr, $port, $errno, $errstr, 2);
$success = "#FF0000";
$success_msg = "is closed and cannot be used at this time";
if ($fp) {
$success = "#99FF66";
$success_msg = "is open and ready to be used";
}
@fclose($fp);
echo '<div style="width:300px;background:' .$success. ';padding:10px;font-family:arial;font-size:12px;">
The address <b>"' .$addr. ':' .$port. '"</b> ' .$success_msg. '
</div>';
}
else if ($_GET["port"] && $_GET["port2"]) {
$p1 = $_GET["port"];
$p2 = $_GET["port2"];
if ($p1 == $p2) {
$fp = @fsockopen($addr, $port, $errno, $errstr, 1);
$success = "#FF0000";
$success_msg = "is closed and cannot be used at this time";
if ($fp) {
$success = "#99FF66";
$success_msg = "is open and ready to be used";
}
@fclose($fp);
echo '<div style="width:300px;background:' .$success. ';padding:10px;font-family:arial;font-size:12px;">
The address <b>"' .$addr. ':' .$port. '"</b> ' .$success_msg. '
</div>';
}
else {
if ($p1 < $p2) {
$s = $p1;
$st = $p1;
$e = $p2;
}
else if ($p2 < $p1) {
$s = $p2;
$st = $p2;
$e = $p1;
}
while ($s <= $e) {
$fp = @fsockopen($addr, $s, $errno, $errstr, 1);
if ($fp) {
$p_open = $p_open. " " .$s;
$p_1 = 1;
}
@fclose($fp);
$s++;
}
if ($p_1) {
$c = "#99FF66";
$m = "On the address <b>" .$addr. "</b> and port range <b>" .$st. "-" .$e. "</b> the following ports were open: " .$p_open;
}
else {
$c = "#FF0000";
$m = "No ports on the address <b>" .$addr. "</b> and port range <b>" .$st. "-" .$e. "</b> were open";
}
echo '<div style="width:300px;background:' .$c. ';padding:10px;font-family:arial;font-size:12px;">' .$m. '</div>';
}
}
}
echo 'Execution Time: '.(microtime(true)-$starttime).' ms';
?>
</div>
</div>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment