-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
151 lines (124 loc) · 4.8 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
define( "TIMEOUT", 2 );
if ( isset( $_GET[ "IP" ] ) && isset( $_GET[ "port" ] ) ) {
$IP = $_GET[ "IP" ];
$port = $_GET[ "port" ];
$connection = @fsockopen( $IP, $port, $errno, $errstr, TIMEOUT );
if( is_resource( $connection ) )
{
exit( "1" );
fclose( $connection );
}
else
{
exit( "0" );
}
}
?>
<html>
<head>
<title>Port finder</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Port finder</h1>
<div class="col-md-4">
<div class="form-group">
<label for="input-ip">IP</label>
<input class="form-control" id="input-ip" name="ip">
</div>
<div class="form-group">
<label for="input-range-start">Range start</label>
<input type="number" class="form-control" id="input-range-start" name="range-start">
</div>
<div class="form-group">
<label for="input-range-end">Range end</label>
<input type="number" class="form-control" id="input-range-end" name="range-end">
</div>
<div class="well" id="feedback-message" style="display: none;"></div>
<button class="btn btn-primary" id="button-test" onclick="testPorts();">Test ports</button>
<input type="checkbox" checked="checked" id="checkbox-clear-table">
<label for="checkbox-clear-table">Clear results</label>
</div>
<div id="results-table-container" class="col-md-8 table-responsive"
style="overflow: auto; max-height: 600px">
<table class="table" id="results-table">
<thead>
<tr>
<th>IP</th>
<th>Port</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3" id="initial-message">Hit <b>test ports</b>!</td>
</tr>
</tbody>
</table>
</div>
</div>
<script>
var inputIP = $( "#input-ip" );
var inputRangeStart = $( "#input-range-start" );
var inputRangeEnd = $( "#input-range-end" );
var buttonTest = $( "#button-test" );
var checkboxClearTable = $( "#checkbox-clear-table" );
var feedbackMessage = $( "#feedback-message" );
var resultsTable = $( "#results-table" );
function showFeedbackMessage( msg ) {
feedbackMessage.text( msg );
feedbackMessage.fadeIn( 300 );
}
function testIPPorts( IP, rangeStart, rangeEnd ) {
if ( checkboxClearTable.is( ":checked" ) ) {
resultsTable.find( "tbody tr" ).remove();
}
function testPort( portNumber ) {
$.ajax( ".", {
data: { IP: IP, port: portNumber },
complete: function( response ) {
showFeedbackMessage( "Tested " + IP + ":" + portNumber );
// Add row to results table
if ( response.responseText == "1" ) {
var resultRow = "<tr class='success'>";
resultRow += "<td>" + IP + "</td><td>" + portNumber + "</td><td>Open</td>";
resultRow += "</tr>";
resultsTable.find( "#initial-message" ).remove();
resultsTable.find( "tbody" ).append( resultRow );
$( "#results-table-container" ).scrollTop( 999999999 );
}
}
} );
}
while( rangeStart <= rangeEnd ) {
testPort( rangeStart );
rangeStart++;
}
}
function testPorts() {
var IPs = inputIP.val().split( "," );
var rangeStart = parseInt( inputRangeStart.val() );
var rangeEnd = parseInt( inputRangeEnd.val() );
if ( ! IPs.length ) {
alert( "Check the IP value." );
}
if ( isNaN( rangeStart ) || isNaN( rangeEnd ) || ! ( rangeStart <= rangeEnd ) ) {
alert( "Check the range start and range end values." );
return;
}
showFeedbackMessage( "Initializing" );
buttonTest.addClass( "disabled" );
setTimeout( function() { buttonTest.removeClass( "disabled" ); }, 1000 );
for( var i = 0; i < IPs.length; i++ ) {
var IP = IPs[ i ].replace( /^\s+|\s+$|:\d+$/g, "" );
testIPPorts( IP, rangeStart, rangeEnd );
}
}
</script>
</body>
</html>