How to use the haraka-net-utils.get_ips_by_host function in haraka-net-utils

To help you get started, we’ve selected a few haraka-net-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github haraka / Haraka / plugins / mail_from.is_resolvable.js View on Github external
addresses.forEach(addr => {
            // Handle MX records that are IP addresses
            // This is invalid - but a lot of MTAs allow it.
            if (net_utils.get_ipany_re('^\\[','\\]$','').test(addr.exchange)) {
                connection.logwarn(plugin, domain + ': invalid MX ' +
                        addr.exchange);
                if (c.allow_mx_ip) {
                    records[addr.exchange] = 1;
                }
                return;
            }
            pending_queries++;
            net_utils.get_ips_by_host(addr.exchange, (err2, addresses2) => {
                pending_queries--;
                if (!txn) return;
                if (err2 && err2.length === 2) {
                    results.add(plugin, {msg: err2[0].message});
                    connection.logdebug(plugin, domain + ': MX ' +
                            addr.priority + ' ' + addr.exchange +
                            ' => ' + err2[0].message);
                    check_results();
                    return;
                }
                connection.logdebug(plugin, domain + ': MX ' + addr.priority +
                        ' ' + addr.exchange + ' => ' + addresses2);
                for (let i=0; i < addresses2.length; i++) {
                    // Ignore anything obviously bogus
                    if (net.isIPv4(addresses2[i])){
                        if (plugin.re_bogus_ip.test(addresses2[i])) {
github haraka / Haraka / plugins / mail_from.is_resolvable.js View on Github external
exports.implicit_mx = function (connection, domain, mxDone) {
    const plugin = this;
    const txn = connection.transaction;

    net_utils.get_ips_by_host(domain, (err, addresses) => {
        if (!txn) return;
        if (!addresses || !addresses.length) {
            txn.results.add(plugin, {fail: 'has_fwd_dns'});
            return mxDone(((plugin.cfg.main.reject_no_mx) ? DENY : DENYSOFT),
                'No MX for your FROM address');
        }

        connection.logdebug(plugin, domain + ': A/AAAA => ' + addresses);
        let records = {};
        for (let i=0; i < addresses.length; i++) {
            const addr = addresses[i];
            // Ignore anything obviously bogus
            if (net.isIPv4(addr)){
                if (plugin.re_bogus_ip.test(addr)) {
                    connection.logdebug(plugin, domain + ': discarding ' + addr);
                    continue;
github haraka / Haraka / plugins / helo.checks.js View on Github external
// Set-up timer
    let timed_out = false;
    const timer = setTimeout(() => {
        timed_out = true;
        const err = new Error('timeout resolving: ' + host);
        err.code = dns.TIMEOUT;
        plugin.logerror(err);
        return cb(err);
    }, (plugin.cfg.main.dns_timeout || 30) * 1000);

    // fully qualify, to ignore any search options in /etc/resolv.conf
    if (!/\.$/.test(host)) { host = host + '.'; }

    // do the queries
    net_utils.get_ips_by_host(host, (errs, ips) => {
        // results is now equals to: {queryA: 1, queryAAAA: 2}
        if (timed_out) { return; }
        if (timer) { clearTimeout(timer); }
        let err = '';
        for (const error of errs) {
            switch (error.code) {
                case dns.NODATA:
                case dns.NOTFOUND:
                case dns.SERVFAIL:
                    continue;
                default:
                    err = `${err}, ${error.message}`;
            }
        }
        if (!ips.length && err) { return cb(err, ips); }
        // plugin.logdebug(plugin, host + ' => ' + ips);
github haraka / Haraka / plugins / lookup_rdns.strict.js View on Github external
domains.forEach(rdns2 => {
            net_utils.get_ips_by_host(rdns2, (err2, addresses) => {
                total_checks--;

                if (err2 && err2.length) {
                    if (!called_next && !total_checks) {
                        connection.auth_results("iprev=fail");
                        _dns_error(connection, call_next, err2[0], rdns2, plugin,
                            fwd_nxdomain, fwd_dnserror);
                    }
                    return;
                }
                for (let j = 0; j < addresses.length ; j++) {
                    if (addresses[j] === connection.remote.ip) {
                        // We found a match, call next() and return
                        if (!called_next) {
                            connection.auth_results("iprev=pass");
                            return call_next(OK, rdns2);