[Javascript] Hub Finder

We seem to go through cycles of lost hubs due to IP changes, etc. This little HTML file contains a small javascript that does a brute force iteration through the network segment to locate any hubs that may be on it. The iteration runs asynchronously so hubs are reported as they respond; depending on the number of IPs you ask it to check the file may run for several minutes.

image

Given the inputs above the file would have searched the range of 192.168.3.2-192.168.3.101 inclusive. If want to do the entire segment use 253 as your number of iterations.

HTML/JS Source
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript">
	function hubSearch(ipBase, iterations){
	  hubList =""
	  for(i=2; i<iterations; i++){
		var fileURL = "http://"+ipBase+i+"/ui2/images/hub-logo.svg";
		try{
		imageExists(fileURL, function(exists, url) {
			if(exists) {
				hubList+="<br />"+url.substring(7,url.indexOf("/",8));
				document.getElementById('oList').innerHTML = "<p>Hubs Found:"+hubList+"</p>";
			}
		});
		} catch (ex) {}
	  }
	}

     function imageExists(url, callback) {
      var img = new Image();
      img.onload = function() { callback(true, url); };
      img.onerror = function() { callback(false, url); };
      img.src = url;
    }		
</script>
</head>
<body>
	IP Base: <input type="text" value="192.168.1." id="base"/><br />
	IP Iterations: <input type="text" value="50" id="iter"/><br />
	<button onclick="hubSearch(document.getElementById('base').value,document.getElementById('iter').value)">Search</button>
	<div id="oList"></div>
</body
</html>
9 Likes

Really interesting code and great utility. Thanks a bunch!

2 Likes