@dkvz/iplookup-cli
Advanced tools
Comparing version 1.0.2 to 2.0.0
#!/usr/bin/env node | ||
require('dotenv').config() | ||
const yargs = require('yargs/yargs') | ||
const { hideBin } = require('yargs/helpers') | ||
const path = require('path') | ||
@@ -16,10 +18,8 @@ const geoip = require('./lib/geoip') | ||
async function showIpInfo(ips) { | ||
async function showIpInfo(ips, short = false) { | ||
await geoip.openReaders(geoCityPath, geoAsnPath) | ||
for (ip of ips) { | ||
console.log('---') | ||
let asTable; | ||
const city = geoip.getCity(ip) | ||
const asn = geoip.getASN(ip) | ||
console.log(`IP Address: ${ip}`) | ||
let asTable | ||
if (city) { | ||
@@ -37,11 +37,17 @@ asTable = { | ||
if (asn) { | ||
asTable['AS'] = asn.autonomousSystemNumber; | ||
asTable['Org'] = asn.autonomousSystemOrganization; | ||
asTable['AS net'] = asn.network; | ||
asTable['AS'] = asn.autonomousSystemNumber | ||
asTable['Org'] = asn.autonomousSystemOrganization | ||
asTable['AS net'] = asn.network | ||
} | ||
// Wanted this at the end | ||
// At some point I realized I needed this: | ||
if (city && city.traits && city.traits.network) { | ||
asTable['IP net'] = city.traits.network | ||
} | ||
console.table(asTable) | ||
if (short) { | ||
console.log(asTable.ISO ? asTable.ISO : '??') | ||
} else { | ||
console.log(`IP Address: ${ip}`) | ||
console.table(asTable) | ||
console.log('---') | ||
} | ||
//console.log(JSON.stringify({ ...city, ...asn }, null, 2)) | ||
@@ -51,6 +57,17 @@ } | ||
// TODO We could print USAGE if arguments are missing. | ||
if (process.argv < 3) die('Missing IP address(es) as argument(s)') | ||
const ipArgs = process.argv.splice(2) | ||
showIpInfo(ipArgs) | ||
const argv = yargs(hideBin(process.argv)) | ||
.usage('$0 [-s] IP_ADDRESS1 IP_ADDRESS2 ...') | ||
.option('short', { | ||
alias: 's', | ||
describe: 'Only show the country code', | ||
boolean: true, | ||
default: false | ||
}) | ||
.help() | ||
.parse() | ||
if (argv._.length < 1) die('Missing IP address(es) as argument(s)') | ||
//const ipArgs = process.argv.splice(2) | ||
showIpInfo(argv._, argv.short) |
{ | ||
"name": "@dkvz/iplookup-cli", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Queries IP location databases and shows info on the owner and their IP ranges", | ||
@@ -17,4 +17,5 @@ "main": "iplookup.js", | ||
"@maxmind/geoip2-node": "^3.1.0", | ||
"dotenv": "^10.0.0" | ||
"dotenv": "^10.0.0", | ||
"yargs": "^17.5.1" | ||
} | ||
} |
@@ -15,5 +15,15 @@ # iplookup-cli | ||
The `-s` option makes it so only the country code is printed. | ||
## NPM package | ||
Can be installed as a CLI tool from npm: | ||
``` | ||
npm install -g @dkvz/iplookup-cli | ||
``` | ||
Which should allow you to use the command `iplookup-node`. For instance: `iplookup-node 8.8.8.8 1.1.1.1`. | ||
# TODO | ||
- [x] Add error handling | ||
- [ ] Could be a CLI npm package. Just set the env varibles globally in bashrc or something to set your own database paths | ||
- [x] Could be a CLI npm package. Just set the env varibles globally in bashrc or something to set your own database paths | ||
- [ ] Add a flag to query the GeoIP API instead of using the local DBs |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4642
104
28
3
+ Addedyargs@^17.5.1
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)