Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dkvz/iplookup-cli

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dkvz/iplookup-cli - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

43

iplookup.js
#!/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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc