Provides a quick way of testing IP addresses against a list of trusted “network providers”. The project comes out of a use-case where I want to maintain a real-time IP blocklist for my WordPress & email servers, but I want to avoid accidentally blocking Googlebot, GMail and MS Outlook servers.
There’s a built-in list of trusted providers for common well-trusted services, and these can auto-updated themselves from publicly available IP lists, or DNS lookups.
Installation
# Add trusted-network-providers to your project. npm install @headwall/trusted-network-providers
Example usage
/**
* test.js
*/
const trustedProviders = require('./index');
/**
* Add the built-in proicers including Googlebot, PayPal and a few others.
*/
trustedProviders.loadDefaultProviders();
/**
* Force the dynamically-updated ptoviders to refresh themselves by whatever
* means they use.
*/
trustedProviders.reloadAll()
.then(() => {
const ipAddresses = [
'11.22.33.44',
'123.123.123.123',
'66.249.66.87',
];
ipAddresses.forEach((ipAddress) => {
let providerName = trustedProviders.getTrustedProvider(ipAddress);
if (!providerName) {
providerName = '_wild_';
}
console.log(`${ipAddress} => ${providerName}`);
});
console.log('Finished IP lookups');
});You can periodically call trustedProviders.reloadAll() to refresh IP address lists. They won’t change very often, but if you’ve got a long-running service then reloading the providers a couple of times a day is probably a good idea.