From 7cbe2e11afe091f4d8d1c3136ef02556e9a531c8 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Fri, 11 Dec 2015 17:08:45 +0200 Subject: Switch to netmask library --- index.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index d286152..293a0c0 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ import './style.scss' +import { Netmask } from 'netmask' import React from 'react' import ReactDOM from 'react-dom' @@ -39,21 +40,18 @@ class IPAddress extends React.Component { } getNetmask = () => { - if (this.state.cidr == 0) { - return '0.0.0.0' - } - else { - return [...Array(4)].map((x, octet) => - ((((0xFFFFFFFF << (32 - this.state.cidr)) >>> 0) >>> (3-octet)*8) & 0xFF) - ).join('.') - } + var block = new Netmask(this.getPretty()) + return block.mask + } + + getRange = () => { + var block = new Netmask(this.getPretty()) + return block.first + ' - ' + block.last } getCount = () => { - if (this.state.cidr == 32) { - return 1; - } - return ((0xFFFFFFFF >>> this.state.cidr) >>> 0) + 1 + var block = new Netmask(this.getPretty()) + return block.size } render() { @@ -87,6 +85,10 @@ class IPAddress extends React.Component { {this.getNetmask()} Netmask + + {this.getRange()} + Range + {this.getCount().toLocaleString()} Addresses -- cgit v1.3.1