Open Atrate opened 4 years ago
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?
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"));
Thanks for the js snippet. I'll look into it
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.