-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fallback to whois lookup (#10)
* feat: fallback to whois lookup * docs: update README.md * nit: fix typo in README
- Loading branch information
Showing
6 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const whois = require('whois') | ||
const entryRegex = /^(network:)?Organization(;I)?:\W*(.*)/ | ||
|
||
function WhoIs (ip) { | ||
this.ip = ip | ||
} | ||
|
||
WhoIs.prototype.org = function (cb) { | ||
whois.lookup(this.ip, function (err, data) { | ||
if (err) return cb(err) | ||
|
||
var org = data.split('\n').filter(function (entry) { | ||
return entryRegex.test(entry) | ||
}) | ||
|
||
if (org.length) return cb(null, org[0].replace(entryRegex, '$3')) | ||
else return cb() | ||
}) | ||
} | ||
|
||
module.exports = function (ip) { | ||
return new WhoIs(ip) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters