Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check port availability in client-side JavaScript?

Is it possible to detect in JavaScript (in the browser) if a port is disabled by the firewall or router?

like image 353
Danny Fox Avatar asked Feb 03 '23 06:02

Danny Fox


2 Answers

No, with pure javascript this is not possible (aside of making http requests to the specific ports, but those results mean little), what you can do however is check from the outside (in other words your server) whether the specific port is open. Another option would be to use a java applet or browser plugin which could do this for you if you really need it, in which case there are various open source tools which you could probably port if you have the necessary experience with those. Do note however that this isn't exactly user friendly. (Either way, it would be useful if you would describe the exact scenario where you need this, as there might be an altogether different solution.)

like image 121
David Mulder Avatar answered Feb 04 '23 19:02

David Mulder


You can only see if the expected response is there or not.

One has to stay in the boundaries of HTTP when using javascript.

Of course you can send an Ajax request on whatever port of server and see if you get an error. If you want to check port for current machine then probably sending a request on "localhost:843" could help.

But the error could be of some other reasons and not necessarily firewall issue.

We need more information to help you out.

like image 39
Piyush-Ask Any Difference Avatar answered Feb 04 '23 21:02

Piyush-Ask Any Difference