summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorYuval Adam <yuval@y3xz.com>2015-12-11 17:08:45 +0200
committerYuval Adam <yuval@y3xz.com>2015-12-11 17:08:45 +0200
commit7cbe2e11afe091f4d8d1c3136ef02556e9a531c8 (patch)
treef6cc0ae73281b17c06c523c544c6af9c3a9267d8 /index.js
parentf65b28962d4436f4c12b22d5c51cb3ca39918a92 (diff)
Switch to netmask library
Diffstat (limited to 'index.js')
-rw-r--r--index.js26
1 files changed, 14 insertions, 12 deletions
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 {
<span className="value">{this.getNetmask()}</span>
<span className="label">Netmask</span>
</span>
+ <span className="range">
+ <span className="value">{this.getRange()}</span>
+ <span className="label">Range</span>
+ </span>
<span className="count">
<span className="value">{this.getCount().toLocaleString()}</span>
<span className="label">Addresses</span>