Created
December 29, 2018 22:47
-
-
Save sploders101/926099f58228b2aae7a389a3fdebedcb to your computer and use it in GitHub Desktop.
Simple functions for performing netmask checks on an IP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function IPBInt(ip) { | |
const iparr = ip.split("."); | |
let bip = 0n; | |
for(let i=0;i<iparr.length;i++) { | |
bip = bip << 8n; | |
bip += BigInt(iparr[i]); | |
} | |
return bip; | |
} | |
function maskMatch(ip,dest,mask) { | |
ip = IPBInt(ip); | |
dest = IPBInt(dest); | |
mask = IPBInt(mask); | |
return ((~(ip^dest))&mask)===mask; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment