code: function isLocal(ip) {
    // IPv6
    if (!!~ip.indexOf(':')) {
      return (/^::1$/.test(ip) || /^fe80/i.test(ip) || /^fc[0-9a-f]{2}/i.test(ip) || /^fd[0-9a-f]{2}/i.test(ip)
      );
    }
  
    // IPv4
    var parts = ip.split('.').map(function (n) {
      return parseInt(n, 10);
    });
  
    return parts[0] === 10 || parts[0] === 192 && parts[1] === 168 || parts[0] === 172 && parts[1] >= 16 && parts[1] <= 31;
  }
docs: IP should be considered as internal when:
  ::1 - IPv6  loopback
  fc00::/8
  fd00::/8
  fe80::/8
  10.0.0.0    -> 10.255.255.255  (10/8 prefix)
  127.0.0.0   -> 127.255.255.255 (127/8 prefix)
  172.16.0.0  -> 172.31.255.255  (172.16/12 prefix)
  192.168.0.0 -> 192.168.255.255 (192.168/16 prefix)