-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
118 lines (106 loc) · 3.54 KB
/
index.php
File metadata and controls
118 lines (106 loc) · 3.54 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebSocket Server Scanner</title>
<style>
.loader {
border: 36px solid #f3f3f3; /* Light grey */
border-top: 36px solid red;
border-radius: 50%;
width: 90px;
height: 90px;
animation: spin 2s linear infinite;
position: relative;
top: -10%;
left: 20%;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
body{
font-family: Arial;
font-size: 30px;
}
</style>
</head>
<body>
<?php
if(isset($_COOKIE["cs3ip"])){
echo $_COOKIE["cs3ip"];
header("Location: webs.php");
}
?>
<div style="display:none">
<label for="port">Port:</label>
<input type="number" id="port" value="8080">
</div>
<button style="display:none" id="scanButton">Scan</button>
<div style="position: fixed; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);text-align: center;justify-content: center; width: 300px; height: 300px;">
<div class="loader"></div>
<div id="resultContainer"></div>
</div>
<script>
setTimeout(click, 100)
function click(){
document.getElementById('scanButton').click();
}
</script>
<script>
document.getElementById('scanButton').addEventListener('click', async () => {
const startIp = '<?php $localIp = getHostByName(getHostName()); echo substr($localIp, 0, strrpos($localIp, '.')).".2";?>';
const endIp = '<?php $localIp = getHostByName(getHostName()); echo substr($localIp, 0, strrpos($localIp, '.')).".254";?>';
const port = parseInt(document.getElementById('port').value, 10);
const resultContainer = document.getElementById('resultContainer');
resultContainer.innerHTML = 'Scanning network for CS3...';
const scanNetwork = async () => {
const ipList = [];
const start = startIp.split('.').map(Number);
const end = endIp.split('.').map(Number);
for (let i = start[0]; i <= end[0]; i++) {
for (let j = start[1]; j <= end[1]; j++) {
for (let k = start[2]; k <= end[2]; k++) {
for (let l = start[3]; l <= end[3]; l++) {
ipList.push(`${i}.${j}.${k}.${l}`);
}
}
}
}
const results = await Promise.all(ipList.map(ip => checkWebSocketServer(ip, port)));
const openServers = results.filter(result => result.status === 'open').map(result => result.ip);
return openServers;
};
const checkWebSocketServer = async (ip, port) => {
return new Promise(resolve => {
const ws = new WebSocket(`ws://${ip}:8080/socket.io/?EIO=3&transport=websocket`);
ws.onopen = () => {
ws.close();
resolve({ ip, status: 'open' });
};
ws.onerror = () => {
resolve({ ip, status: 'closed' });
};
ws.onclose = () => {
resolve({ ip, status: 'closed' });
};
});
};
let servers = await scanNetwork();
let resultText = servers.length > 0 ? `Found CS3 at:<br>${servers.join('<br>')}` : 'No CS3 found.';
servers.length > 0 ? document.write("cs3 found"):alert("no cs3 found");
resultContainer.innerHTML = resultText;
if(servers.length < 1){
let servers = prompt('enter ip here:');
document.cookie = "cs3ip="+servers+"; expires=Thu, 18 Dec 2033 12:00:00 UTC; path=/";
window.location.replace("webs.php");
}
else{
document.cookie = "cs3ip="+servers+"; expires=Thu, 18 Dec 2033 12:00:00 UTC; path=/";
window.location.replace("webs.php");
}
});
</script>
</body>
</html>