1 | # dnsbl
|
2 | [![](https://img.shields.io/npm/v/dnsbl.svg?style=flat)](https://www.npmjs.org/package/dnsbl) [![](https://img.shields.io/npm/dm/dnsbl.svg)](https://www.npmjs.org/package/dnsbl) [![](https://packagephobia.com/badge?p=dnsbl)](https://packagephobia.com/result?p=dnsbl)
|
3 | > Query DNS-based blackhole lists
|
4 |
|
5 | Support both IPv4 and IPv6 queries.
|
6 |
|
7 | ## Installation
|
8 | ```sh
|
9 | $ npm i dnsbl
|
10 | ```
|
11 |
|
12 | ## Usage
|
13 | ```js
|
14 | import {lookup, batch} from 'dnsbl';
|
15 |
|
16 | await lookup('127.0.0.2', 'zen.spamhaus.org');
|
17 | // true
|
18 |
|
19 | await lookup('127.0.0.2', 'zen.spamhaus.org', {includeTxt: true});
|
20 | // {
|
21 | // listed: true,
|
22 | // txt: [['some txt'], ['another txt']]
|
23 | // }
|
24 |
|
25 | await batch(['1.2.3.4', '5.6.7.8'], ['dnsbl.somelist.net', 'dnsbl.someotherlist.net']);
|
26 | // [
|
27 | // { blacklist: 'dnsbl.somelist.net', address: '1.2.3.4', listed: true },
|
28 | // { blacklist: 'dnsbl.somelist.net', address: '5.6.7.8', listed: false },
|
29 | // { blacklist: 'dnsbl.someotherlist.net', address: '1.2.3.4', listed: true },
|
30 | // { blacklist: 'dnsbl.someotherlist.net', address: '5.6.7.8', listed: false }
|
31 | // ]
|
32 | ```
|
33 |
|
34 | ## API
|
35 | ### lookup(address, blacklist, [options])
|
36 | - `address`: *string* an IP address.
|
37 | - `blacklist`: *string* the hostname of the blacklist to query.
|
38 |
|
39 | Returns a `Promise` that resolves to `true` or `false`, indicating if the address is listed (e.g. the DNS query returned a non-empty result). Will reject on error.
|
40 |
|
41 | If the `includeTxt` option is set, it will return an `Object` with these properties:
|
42 | - `listed` *boolean* - a boolean indicating if the address is listed on the blacklist.
|
43 | - `txt` *string[]* - an array of resolved TXT records for the address.
|
44 |
|
45 | ### batch(addresses, blacklists, [options])
|
46 | - `addresses` *string* or *Array* - one or more IP addresses.
|
47 | - `blacklists` *string* or *Array* - one or more blacklist hostnames.
|
48 |
|
49 | Returns a `Promise` that resolve to a `results` object (see below).
|
50 |
|
51 | ### `options` object
|
52 | - `servers` *string* or *Array* - DNS servers to use. Pass a falsy value to use the system resolvers. Default: `['208.67.220.220', '208.67.222.222', '2620:119:35::35', '2620:119:53::53']`.
|
53 | - `timeout` *number* - timout in milliseconds. Default: `5000`.
|
54 | - `concurrency` *number* - number of concurrent queries. Default: `64`.
|
55 | - `includeTxt` *boolean* - include txt records if IP is blacklisted. Default: `false`.
|
56 |
|
57 | ### `results` object
|
58 | The `results` object is an array of objects with these properies:
|
59 | - `address` *string* - the IP address.
|
60 | - `blacklist` *string* - the blacklist hostname.
|
61 | - `listed` *boolean* - a boolean indicating if the address is listed on the blacklist.
|
62 | - `txt` *string[]* - an array of resolved TXT records for the address.
|
63 |
|
64 | © [silverwind](https://github.com/silverwind), distributed under BSD licence
|