Ning icon indicating copy to clipboard operation
Ning copied to clipboard

Allow scanning specified IPs

Open Atrate opened this issue 3 years ago • 3 comments

It would be nice if Ning supported port scanning a specified IP without having to scan the whole subnet first — it would also allow for port scanning IPs outside the LAN.

Atrate avatar Aug 14 '20 06:08 Atrate

Good point and a useful feature.

Not yet sure how that would fit into the ui. Maybe a search option in the toolbar, where you could enter the IP?

csicar avatar Sep 18 '20 21:09 csicar

Yes I think that is a good method I'd like to request CIDR in the search bar, so you can say scan a specific IP: 192.168.0.55 or you can do 192.168.0.5/24 <-- note this isn't the actual network address (which should then default to the correct network of "192.168.0.0/24" and then scan 192.168.0.1 - 192.168.0.254 (0 and 255 aren't addressable right?)

here's some javascript that does it I found posted so you don't have to redo the math http://jsfiddle.net/kLjdLadv/

    function getIpRangeFromAddressAndNetmask(str) {
      var part = str.split("/"); // part[0] = base address, part[1] = netmask
      var ipaddress = part[0].split('.');
      var netmaskblocks = ["0","0","0","0"];
      if(!/\d+\.\d+\.\d+\.\d+/.test(part[1])) {
        // part[1] has to be between 0 and 32
        netmaskblocks = ("1".repeat(parseInt(part[1], 10)) + "0".repeat(32-parseInt(part[1], 10))).match(/.{1,8}/g);
        netmaskblocks = netmaskblocks.map(function(el) { return parseInt(el, 2); });
      } else {
        // xxx.xxx.xxx.xxx
        netmaskblocks = part[1].split('.').map(function(el) { return parseInt(el, 10) });
      }
      var invertedNetmaskblocks = netmaskblocks.map(function(el) { return el ^ 255; });
      var baseAddress = ipaddress.map(function(block, idx) { return block & netmaskblocks[idx]; });
      var broadcastaddress = ipaddress.map(function(block, idx) { return block | invertedNetmaskblocks[idx]; });
      return [baseAddress.join('.'), broadcastaddress.join('.')];
    }
	alert(getIpRangeFromAddressAndNetmask("192.168.138.0/23"));
	alert(getIpRangeFromAddressAndNetmask("192.168.138.0/255.255.254.0"));

I've tested

alert(getIpRangeFromAddressAndNetmask("192.168.138.33/23"));
    alert(getIpRangeFromAddressAndNetmask("192.168.138.76/24"));

and some various others

it seems to also take incorrectly formatted subnet masks as input too (as their example shows)

alert(getIpRangeFromAddressAndNetmask("192.168.138.0/255.255.254.0"));

G2G2G2G avatar Oct 27 '21 23:10 G2G2G2G

Thanks for the js snippet. I'll look into it

csicar avatar Oct 28 '21 07:10 csicar