Since all the other ways don't work and since JavaScript is so limited. Here's my piece of code.. I am not really good at javas- but the logic is that if an IP responds in a specific amount of time, then it's the gateway IP. If not then it's not. The more gateway IPs are in the list, the better, however there are still downs of using this script. Since most gateway IPs are actually occupied by devices on other networks. This might cause problems and results may not be accurate.
var responses = [];
var ips = ["192.168.1.1", "192.168.0.1", "10.0.0.138", "192.168.2.1", "192.168.254.254", "10.0.1.1", "192.168.3.1", "10.10.1.1", "10.0.0.1", "10.0.0.2", "10.1.1.1", "192.168.11.1", "192.168.0.30", "192.168.0.50", "192.168.0.10", "192.168.0.101", "192.168.15.1", "10.90.90.90", "192.168.8.1", "192.168.86.1", "192.168.100.1", "192.168.123.254", "192.168.16.1", "192.168.10.1", "192.168.20.1", "192.168.30.1", "192.168.62.1", "192.168.102.1", "192.168.0.227", "192.168.10.50", "10.1.10.1", "192.168.0.3", "192.168.168.168", "192.168.50.1", "192.168.55.1", "192.168.251.1", "192.168.0.254", "192.168.0.100", "192.168.10.10", "192.168.10.100", "192.168.223.100", "200.200.200.5", "192.168.4.1", "192.168.100.100", "192.168.2.254"];
var length = ips.length
for (var i = 0; i < length; i++){
(async function(){
var connection = new WebSocket('ws://' + ips[i] + ':80');
await new Promise (function(res){
var timeout = setTimeout(function() {
console.log("Socket connection timeout", connection.readyState);
console.log(connection.url);
if (connection.readyState == 3){
responses.push('valid')
alert(connection.url);
} else {
responses.push('invalid')
}
connection.close();
}, 5000);
res();
});
})();
}