Skip to content

Instantly share code, notes, and snippets.

@iongion
iongion / networktools
Created February 13, 2014 14:49
Check if IP or hostnames are local, with loose restrictions on host name
function ipv42long(addr) {
var octets = addr.split('.')
return (parseInt(octets[0]) * 16777216) + (parseInt(octets[1]) * 65536) + (parseInt(octets[2]) * 256) + parseInt(octets[3])
}
function isPrivateIP(addr) {
var is_private = false,
ranges = [
['10.0.0.0', '10.255.255.255'],
['172.16.0.0', '172.31.255.255'],