diff options
| author | Yuval Adam <yuval@y3xz.com> | 2015-12-09 13:28:31 +0200 |
|---|---|---|
| committer | Yuval Adam <yuval@y3xz.com> | 2015-12-09 13:31:07 +0200 |
| commit | 758d6f2c4a6db148fe1912ce28f88465e3e79d26 (patch) | |
| tree | 950eb7b9542f1945412867d51cd3dd2e23585bf2 | |
| parent | 0f8d2df1aad4af3dbc5c07ea79fdef8dc3ba3082 (diff) | |
Add netmask calculation
| -rw-r--r-- | index.js | 22 | ||||
| -rw-r--r-- | style.scss | 5 |
2 files changed, 24 insertions, 3 deletions
@@ -34,9 +34,22 @@ class IPAddress extends React.Component { } } - render() { - var pretty = this.state.octets.join('.') + '/' + this.state.cidr + getPretty = () => { + return this.state.octets.join('.') + '/' + this.state.cidr + } + 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('.') + } + } + + render() { return <div className="ip-address"> <div className="address"> {[...Array(4)].map((x, octet) => @@ -61,6 +74,11 @@ class IPAddress extends React.Component { )} </ol> </div> + + <div className="details"> + <span className="netmask">Netmask: {this.getNetmask()}</span> + </div> + </div> } } @@ -63,7 +63,10 @@ body { &:nth-child(2) ol li.bit.unmasked { background-color: lighten($color_b, $octet_lighten); } &:nth-child(3) ol li.bit.unmasked { background-color: lighten($color_c, $octet_lighten); } &:nth-child(4) ol li.bit.unmasked { background-color: lighten($color_d, $octet_lighten); } - ol li.bit.masked { background-color: lighten($color_e, $octet_lighten); } + ol li.bit.masked { + background-color: lighten($color_e, $octet_lighten); + color: lighten($color_e, 22%); + } } } } |
