0

I have an intranet app that periodically checks status of a set of printers by sending it a "Host Status" command. If status returned is "No Response" I display the printer with a red background that user can click and get some additional info. This additional info is the part I need help with.

When clicked, I send a ping command using printer's IP. If I get a "timeout" I have the answer: printer is offline. But I might get a response which means printer is online; "No Response" could be a port issue. However, it seems I can't ping IP:Port since ping uses ICMP and has no concept of port.

How can I check for this in JS/jQuery?

This is what I am using to test for ping response (and IP:Port which I think is useless):

function ping(ip, callback) {
    if (!this.inUse) {
        this.status = 'unchecked';
        this.inUse = true;
        this.callback = callback;
        this.ip = ip;
        var _that = this;
        this.img = new Image();
        this.img.onload = function () {
            _that.inUse = false;
            _that.callback('responded');
        };
        this.img.onerror = function (e) {
            if (_that.inUse) {
                _that.inUse = false;
                _that.callback('responded', e);
            }
        };
        this.start = new Date().getTime();
        this.img.src = "http://" + ip + "/?cachebreaker=" + new Date().getTime();
        this.timer = setTimeout(function () {
            if (_that.inUse) {
                _that.inUse = false;
                _that.callback('timeout');
            }
        }, 1500);
    }
}

Somewhere in script checking status:

$(document).on('click', '.extLink', function () {
    var ip = $(this).data("ip");
    ...
    new ping(ip, function (status, e) {
        if (status == 'responded') {
            $('<p>Printer is reachable. Ping was successful.<br />Checking port 9100.</p>').appendTo('#divInfo');
            new ping(ip + ":9100", function (status, e) { // not sure about this
                if (status == 'timeout') {
                    $('<p>Port 9100 is blocked.</p>').appendTo('#divInfo');
                }
            });
        }
        else if (status == 'timeout') {
            $('<p>Printer is not reachable. Ping failed.</p>').appendTo('#divInfo');
        }
    });
    ...
});
NoBullMan
  • 2,032
  • 5
  • 40
  • 93
  • 2
    jQuery is not a tool for port scanning printers. You may as well ask how you can file your taxes with a spoon. The premise of the question makes no sense. – temporary_user_name Dec 07 '20 at 15:55
  • I use ajax with a web service call to get printer status, not jQuery. Once response is returned as "No Response", I use jQuery function I included to ping the IP to see if that's the reason "No response" was returned. I was wondering if there is a similar way to do the same using port in addition to IP, in case ping responded but port was blocked. – NoBullMan Dec 07 '20 at 17:24
  • I'm a little bit confused. ICMP protocol is useful to verify that an IP address is reachable, but on port 9100 printers use JetDirect protocol that can be verified with telnet, so you shoud be check printer on the server side. – Lety Dec 07 '20 at 19:14
  • ...and your ping class doesn't do an ICMP ping, but an http request on port 80. Probably on printer server there is an http server. As I said before, on port 9100 it is not listen an http server... – Lety Dec 08 '20 at 09:09

0 Answers0