New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

check-rkn

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

check-rkn - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

LICENSE.txt

111

index.js
'use strict';
const https = require('https');
const async = require('async');
const path = require('path');
const dns = require('dns');
const fs = require('fs');

@@ -10,3 +12,3 @@ const ip = require('ip');

const base = {
let base = {
"ips": (fs.existsSync(path.join(__dirname, 'ips' + prefix + '.json')))

@@ -23,18 +25,21 @@ ? JSON.parse((fs.readFileSync(path.join(__dirname, 'ips' + prefix + '.json'), 'utf8')))

function check_rkn(check_data, callback) {
let type = (typeof check_data === 'object' && check_data[0])
? (ip.isV4Format(check_data[0]))
? 'ips'
: 'domains'
: (ip.isV4Format(check_data))
? 'ips'
: 'domains';
if (!base[type].length) {
let type = typeof check_data !== 'object'
? ip.isV4Format(check_data) ? 'ip' : 'domain'
: false;
check_data = typeof check_data === 'object' ? check_data : [check_data];
if (!base.ips.length || !base.domains.length) {
clear();
get(type, err => {
get('ips', err => {
if (err) return callback(err);
base[type] = (fs.existsSync(path.join(__dirname, type + prefix + '.json')))
? JSON.parse((fs.readFileSync(path.join(__dirname, type + prefix + '.json'), 'utf8')))
: [];
check(type, check_data, base[type], (err, res) => {
callback(err, res);
get('domains', err => {
if (err) return callback(err);
base['ips'] = (fs.existsSync(path.join(__dirname, 'ips' + prefix + '.json')))
? JSON.parse((fs.readFileSync(path.join(__dirname, 'ips' + prefix + '.json'), 'utf8')))
: [];
base['domains'] = (fs.existsSync(path.join(__dirname, 'domains' + prefix + '.json')))
? JSON.parse((fs.readFileSync(path.join(__dirname, 'domains' + prefix + '.json'), 'utf8')))
: [];
check(check_data, type, (err, res) => {
callback(err, res);
})
})

@@ -44,3 +49,3 @@ })

else {
check(type, check_data, base[type], (err, res) => {
check(check_data, type, (err, res) => {
callback(err, res);

@@ -51,2 +56,49 @@ })

function check(check_data, type, callback) {
async.forEachOf(check_data, function (value, key, callback) {
if (!ip.isV4Format(value)) {
dns.resolve4(value, (err, addresses) => {
if (err) {
check_data.splice(key, 1, {
"domain": value,
"error": err.code
});
}
else {
check_data.splice(key, 1, {
"domain": value,
"block": !!(base.domains.filter(d => d === value)).length,
"ips": addresses.map(address => {
return {
"ip": address,
"block": !!(base.ips.filter(i =>
ip.cidrSubnet(i.indexOf('/')+1?i:i+'/32').contains(address))).length
}
})
});
}
callback()
})
}
else {
check_data.splice(key, 1, {
"ip": value,
"block": !!(base.ips.filter(i =>
ip.cidrSubnet(i.indexOf('/')+1?i:i+'/32').contains(value))).length
});
callback()
}
}, function () {
if (type) {
if (type === 'ip') {
check_data = check_data[0].block;
}
else {
check_data = check_data[0].block || !!(check_data[0].ips.filter(d => d.block)).length
}
}
callback(null, check_data)
})
}
function get(type, callback) {

@@ -75,29 +127,2 @@ https.get('https://api.reserve-rbl.ru/api/v2/' + type + '/json', response => {

function check(type, check_data, data, callback) {
if (typeof check_data === 'object') {
if (type === 'ips') {
callback(null, check_data.map(check_d => {
let res = data.filter(d => ip.cidrSubnet(d.indexOf('/')+1?d:d+'/32').contains(check_d));
return {"ip": check_d, "block": !!res.length}
}));
}
else {
callback(null, check_data.map(check_d => {
let res = data.filter(d => d === check_d);
return {"domain": check_d, "block": !!res.length}
}));
}
}
else {
if (type === 'ips') {
let res = data.filter(d => ip.cidrSubnet(d.indexOf('/')+1?d:d+'/32').contains(check_data));
callback(null, !!res.length);
}
else {
let res = data.filter(d => d === check_data);
callback(null, !!res.length);
}
}
}
function clear() {

@@ -104,0 +129,0 @@ (fs.readdirSync(path.join(__dirname))).forEach(function (f) {

{
"name": "check-rkn",
"version": "1.0.0",
"version": "1.0.1",
"description": "Check IP or domain in RKN blocking.",

@@ -31,4 +31,5 @@ "main": "index.js",

"dependencies": {
"async": "^2.6.0",
"ip": "^1.1.5"
}
}

@@ -15,9 +15,11 @@ # Check IP or domain in RKN blocking.

rkn(['105.28.12.143', '104.28.12.143'], (err, res) => {
// Check list IPs
rkn(['216.58.214.110', '108.174.10.10'], (err, res) => {
console.log(res)
});
// [ { ip: '105.28.12.143', block: false },
// { ip: '104.28.12.143', block: true } ]
// [ { ip: '216.58.214.110', block: false },
// { ip: '108.174.10.10', block: true } ]
rkn('104.28.12.143', (err, res) => {
// Check one IP
rkn('108.174.10.10', (err, res) => {
console.log(res)

@@ -27,8 +29,10 @@ });

// Check list domains
rkn(['google.com', 'linkedin.com'], (err, res) => {
console.log(res)
});
// [ { ip: 'google.com', block: false },
// { ip: 'linkedin.com', block: true } ]
// [ { ip: 'google.com', block: false, ips: [ { ip: '216.58.214.110', block: false } ] },
// { ip: 'linkedin.com', block: true, ips: [ { ip: '108.174.10.10', block: true } ] } ]
// Check one domain (and IP)
rkn('linkedin.com', (err, res) => {

@@ -35,0 +39,0 @@ console.log(res)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc