I can't find any information on this and I was wondering if this was even possible? I have a Minecraft server that I want to ping to find out if it is on at a specific port. I want to do this in Javascript but from what I can see that you cant really do that or it hasn't been done before. Are there any plugins or 3rd party Javascript vendors that can acplish this?
For example:
mc.mydomain:25565
Javascript pings the server and it changes the text from online to offline, depending on if it can connect.
Server is: Online
Or
Server is: Offline
I can't find any information on this and I was wondering if this was even possible? I have a Minecraft server that I want to ping to find out if it is on at a specific port. I want to do this in Javascript but from what I can see that you cant really do that or it hasn't been done before. Are there any plugins or 3rd party Javascript vendors that can acplish this?
For example:
mc.mydomain:25565
Javascript pings the server and it changes the text from online to offline, depending on if it can connect.
Server is: Online
Or
Server is: Offline
Share
Improve this question
asked Jun 27, 2012 at 19:43
RizowskiRizowski
3,5985 gold badges24 silver badges31 bronze badges
4 Answers
Reset to default 2If it happened that the Minecraft server actually speak plains HTTP on that port (which is unlikely), then it could work.
Otherwise, no, it can't be done, at least not with current specifications.
Browsers can only talk HTTP (i.e. to web servers) and WebSockets, and the SSL variants thereof. I don't know whether the uping WebRTC protocol would help.
The alternative is to use Flash - AIUI that has a plain TCP socket capability that can be exposed to JS code that might help in these circumstances.
First of all you can't ping ports, as Ping is using ICMP which doesn't have the concept of ports. Ports belong to the transport layer protocols like TCP and UDP.
So, a solution can be the use of a server side language like PHP to perform the query and then you can make an AJAX request to this page in order to retrieve the result. Here is an example in PHP:
<?php
error_reporting(E_ERROR);
$fp = fsockopen('mc.mydomain', 25565, $errno, $errstr, 1);
if (!$fp) {
echo 'no';
} else {
echo 'yes';
fclose($fp);
}
?>
Moreover, to keep your requests fast, you can imagine to cache the result of the above query into a file or a database and refresh its value every couple of minutes (for example by using a cron job) and then serve the cached result to the AJAX request.
From http://www.gnucitizen/static/blog/2006/08/jsportscanner.js , the first hit when you search for "javascript portscan":
var AttackAPI = {
version: '0.1',
author: 'Petko Petkov (architect)',
homepage: 'http://www.gnucitizen'};
AttackAPI.PortScanner = {};
AttackAPI.PortScanner.scanPort = function (callback, target, port, timeout) {
var timeout = (timeout == null)?100:timeout;
var img = new Image();
img.onerror = function () {
if (!img) return;
img = undefined;
callback(target, port, 'open');
};
img.onload = img.onerror;
img.src = 'http://' + target + ':' + port;
setTimeout(function () {
if (!img) return;
img = undefined;
callback(target, port, 'closed');
}, timeout);
};
AttackAPI.PortScanner.scanTarget = function (callback, target, ports, timeout)
{
for (index = 0; index < ports.length; index++)
AttackAPI.PortScanner.scanPort(callback, target, ports[index], timeout);
};
You can only send HTTP(S) or WS(S) request to the domain you are on with JavaScript. A Ping is much too low-level.
If the minecraft server supports HTTP, you can try to use that.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744899599a4599899.html
评论列表(0条)