roccomuso / is-duckduck

Verify that a request is from DuckDuckBot, the Web crawler for DuckDuckGo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is-duckduck

NPM Version Build Status node Dependency Status JavaScript Style Guide

Verify that a request is from DuckDuckBot, the Web crawler for DuckDuckGo

This library implements DuckDuckGo's own verification steps outlined here.

Install

npm install --save is-duckduck

Example

const isDuckDuck = require('is-duckduck')

let ip = '72.94.249.34'
isDuckDuck(ip).then((outcome) => {
  if (outcome) {
    // it's duckduck.
  }
}).catch(console.error)

Example with express

app.enable('trust proxy')

app.use((req, res, next) => {
  let ip = req.ip || req.connection.remoteAddress
  isDuckDuck(ip).then(outcome => {
    if (outcome) {
      res.status(404).text('Nothing to scan') // block duckduck crawler
    } else {
      next() // it's a user
    }
  })
})

Tests

npm test

License

MIT

Author

Rocco Musolino @roccomuso

About

Verify that a request is from DuckDuckBot, the Web crawler for DuckDuckGo

License:MIT License


Languages

Language:JavaScript 100.0%