Coder Social home page Coder Social logo

checkip's Introduction

Go Reference Go Report Card StandWithUkraine

checkip

Sometimes I come across an IP address, for example when reviewing logs. And I'd like to find out more about this numerical label. Checkip is CLI tool and Go library that provides infomation on and security posture of IP addresses. Most checks are passive and active checks (like ping and tls) are not aggressive.

Quick start

go install github.com/jreisinger/checkip@latest
checkip 1.1.1.1

Usage examples

Check an IP address:

❯ checkip 91.228.166.47
--- 91.228.166.47 ---
db-ip.com       Petržalka, Slovakia
dns name        skh1-webredir01-v.eset.com
iptoasn.com     ESET-AS
is on AWS       false
isc.sans.edu    attacks: 0, abuse contact: [email protected]
ping            100% packet loss (5/0), avg round-trip 0 ms
tls             TLS 1.3, exp. 2024/01/02!!, www.eset.com, eset.com
malicious prob. 8% (1/12) ✅

Check multiple IP addresses coming from STDIN:

❯ dig +short eset.sk | checkip
--- 91.228.167.128 ---
db-ip.com       Petržalka, Slovakia
dns name        h3-webredir02-v.eset.com
iptoasn.com     ESET-AS
is on AWS       false
isc.sans.edu    attacks: 0, abuse contact: [email protected]
ping            100% packet loss (5/0), avg round-trip 0 ms
tls             TLS 1.3, exp. 2024/01/02!!, www.eset.com, eset.com
malicious prob. 9% (1/11) ✅
--- 91.228.166.47 ---
db-ip.com       Petržalka, Slovakia
dns name        skh1-webredir01-v.eset.com
iptoasn.com     ESET-AS
is on AWS       false
isc.sans.edu    attacks: 0, abuse contact: [email protected]
ping            100% packet loss (5/0), avg round-trip 0 ms
tls             TLS 1.3, exp. 2024/01/02!!, www.eset.com, eset.com
malicious prob. 8% (1/12) ✅

Use detailed JSON output to filter out those checks that consider the IP address to be malicious:

❯ checkip -j 91.228.166.47 | jq '.checks[] | select(.ipAddrIsMalicious == true)'
{
  "description": "tls",
  "type": "InfoAndIsMalicious",
  "ipAddrIsMalicious": true,
  "ipAddrInfo": {
    "SAN": [
      "www.eset.com",
      "eset.com"
    ],
    "Version": 772,
    "Expiry": "2024-01-02T23:59:59Z"
  }
}

Continuously generate random IP addresses and check them (hit Ctrl-C to stop):

❯ while true; do ./randip; sleep 2; done | checkip 2> /dev/null
--- 155.186.85.125 ---
db-ip.com       Ashburn, United States
dns name        syn-155-186-085-125.res.spectrum.com
iptoasn.com     CHARTER-20115
is on AWS       false
isc.sans.edu    attacks: 0, abuse contact: [email protected]
ping            100% packet loss (5/0), avg round-trip 0 ms
malicious prob. 0% (0/10) ✅
--- 115.159.53.216 ---
db-ip.com       Shenzhen (Futian Qu), China
iptoasn.com     TENCENT-NET-AP Shenzhen Tencent Computer Systems Company Limited
is on AWS       false
isc.sans.edu    attacks: 0, abuse contact: [email protected]
ping            100% packet loss (5/0), avg round-trip 0 ms
malicious prob. 0% (0/10) ✅

Generate 100 random IP addresses and select Russian or Chinese:

❯ ./randip 100 | checkip -p 20 -j 2> /dev/null | jq -r '.ipAddr as $ip | .checks[] | select (.description == "db-ip.com" and (.ipAddrInfo.iso_code == "RU" or .ipAddrInfo.iso_code == "CN")) | $ip'
218.19.226.129
119.32.13.38
139.210.45.205

Find out who is trying to SSH into your Linux system:

❯ sudo journalctl --unit ssh --since "1 hour ago" | \
∙ grep 'Bye Bye' | perl -wlne '/from ([\d\.]+)/ && print $1' | sort | uniq | \
∙ checkip 2> /dev/null
--- 167.172.105.64 ---
db-ip.com       Frankfurt am Main, Germany
iptoasn.com     DIGITALOCEAN-ASN
ping            0% packet loss (5/5), avg round-trip 21 ms
tls             TLS 1.3, exp. 2024/12/27, portal.itruck.com.sa, www.portal.itruck.com.sa
malicious prob. 43% (3/7) 🤏
--- 180.168.95.234 ---
db-ip.com       Shanghai, China
iptoasn.com     CHINANET-SH-AP China Telecom Group
ping            0% packet loss (5/5), avg round-trip 213 ms
malicious prob. 50% (3/6) 🚫

Installation

To install the CLI tool

# optional; to install inside a container
docker run --rm -it golang /bin/bash

go install github.com/jreisinger/checkip@latest

or download a release binary (from under "Assets") for your system and architecture.

Configuration

For some checks to start working you need to register and get an API (LICENSE) key. See the service web site for how to do that. An absent key is not reported as an error, the check is simply not executed and missingCredentials JSON field is set.

Store the keys in $HOME/.checkip.yaml file:

ABUSEIPDB_API_KEY: aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffff11111111222222223333333344444444
MAXMIND_LICENSE_KEY: abcdef1234567890
SHODAN_API_KEY: aaaabbbbccccddddeeeeffff11112222
URLSCAN_API_KEY: abcd1234-a123-4567-678z-a2b3c4b5d6e7
VIRUSTOTAL_API_KEY: aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffff1111111122222222

You can also use environment variables with the same names.

Data used by some checks are downloaded (cached) to $HOME/.checkip/ folder. They are periodically re-downloaded so they are fresh.

Development

Checkip is easy to extend. If you want to add a new way of checking IP addresses:

  1. Write a function of type check.Func.
  2. Add it to check.Funcs variable.

Typical workflow:

make run # test and run

git commit

git tag | sort -V | tail -1
git tag -a v0.2.0 -m "new check func"

git push --follow-tags # will build a new release on GitHub

checkip's People

Contributors

angrychimp avatar dependabot[bot] avatar jreisinger avatar pete911 avatar yvesago avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

checkip's Issues

Implement caching

When running make run too many times I get:

checkip: calling https://www.virustotal.com/api/v3/ip_addresses/218.92.0.158: 429 Too Many Requests

Cache responses for some time to prevent this.

Consider rewrite or new project

  • remove checks that need registration
  • provide info also on FQDN
  • cli should be usable in shell pipelines (input from files and STDIN + performance)
  • JSON + text output

[Feature request] Using IPinfo.io for IP information (IP Geolocation + ASN)

I would like to recommend ipinfo.io for the IP data.

  • Provides highly accurate IP geolocation backed by our probe network infrastructure.
  • Free tier access token supports 50,000 requests per month.
  • IPinfo supports HTTPS/SSL encryption on all endpoints.
  • Tokenless access grants 1,000 requests per day.
  • Includes ASN and hostname information. Supports bulk enrichment through a single API endpoint. We also have a comprehensive integration library.

Usage example:

curl https://ipinfo.io/8.8.8.8
{
    "ip": "8.8.8.8",
    "hostname": "dns.google",
    "anycast": true,
    "city": "Mountain View",
    "region": "California",
    "country": "US",
    "loc": "37.4056,-122.0775",
    "org": "AS15169 Google LLC",
    "postal": "94043",
    "timezone": "America/Los_Angeles"
}

Documentation: https://ipinfo.io/developers

Free IP databases: https://ipinfo.io/products/free-ip-database

nitefood/asn is mentioned in #41. The project is switching to IPinfo for their IP data as well: nitefood/asn#67 (comment)


Consider including IPinfo in the project for accurate data and generous free access. Please let me know what you think. Thank you very much.

Unnecessary downloads of the same data

$ checkip $(dig +short checkip.amazonaws.com)
checkip: wrong IP address: checkip.check-ip.aws.a2z.com.
checkip: wrong IP address: checkip.eu-west-1.prod.check-ip.aws.a2z.com.
checkip: downloading https://iptoasn.com/data/ip2asn-combined.tsv.gz
checkip: downloading https://iplists.firehol.org/files/firehol_level1.netset
checkip: downloading https://download.db-ip.com/free/dbip-city-lite-2022-10.mmdb.gz
checkip: downloading https://download.db-ip.com/free/dbip-city-lite-2022-10.mmdb.gz
checkip: downloading https://download.db-ip.com/free/dbip-city-lite-2022-10.mmdb.gz
checkip: downloading http://cinsscore.com/list/ci-badguys.txt
checkip: downloading https://iplists.firehol.org/files/firehol_level1.netset
checkip: downloading https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt
checkip: downloading https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt
checkip: downloading https://iptoasn.com/data/ip2asn-combined.tsv.gz
checkip: downloading https://iplists.firehol.org/files/firehol_level1.netset
checkip: downloading https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt
checkip: downloading https://iptoasn.com/data/ip2asn-combined.tsv.gz
checkip: downloading http://cinsscore.com/list/ci-badguys.txt
checkip: downloading https://download.db-ip.com/free/dbip-city-lite-2022-10.mmdb.gz
checkip: downloading http://cinsscore.com/list/ci-badguys.txt
checkip: downloading http://cinsscore.com/list/ci-badguys.txt
checkip: downloading https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt
checkip: downloading https://iplists.firehol.org/files/firehol_level1.netset
checkip: downloading https://iptoasn.com/data/ip2asn-combined.tsv.gz
checkip: downloading http://cinsscore.com/list/ci-badguys.txt
checkip: downloading https://download.db-ip.com/free/dbip-city-lite-2022-10.mmdb.gz
checkip: downloading https://iptoasn.com/data/ip2asn-combined.tsv.gz
checkip: downloading https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt
checkip: downloading https://iplists.firehol.org/files/firehol_level1.netset

Review SAN values

What are those unreadable strings?

$ checkip -j 1.1.1.1 | jq -r '.checks[12].info.data.attributes.last_https_certificate.extensions'
{
  "subject_alternative_name": [
    "cloudflare-dns.com",
    "*.cloudflare-dns.com",
    "one.one.one.one",
    "\u0001\u0001\u0001\u0001",
    "\u0001\u0001",
    "\\xa2\\x9f$\\x01",
    "\\xa2\\x9f.\\x01",
    "&\u0006GG\u0011\u0011",
    "&\u0006GG\u0010\u0001",
    "GGd",
    "GGd"
  ]
}

Doesn't work properly on Windows

The windows build doesn't function properly.

It tries using unix paths:

checkip.exe: IPSum: searching 1.1.1.1 in /var/tmp/ipsum.txt: open /var/tmp/ipsum.txt: The system cannot find the path specified.

checkip.exe: DBip: can't load DB file /var/tmp/dbip-city-lite.mmdb: open /var/tmp/dbip-city-lite.mmdb: The system cannot find the path specified.

checkip.exe: IPtoASN: searching 1.1.1.1 in /var/tmp/ip2asn-combined.tsv: open /var/tmp/ip2asn-combined.tsv: The system cannot find the path specified.

checkip.exe: CinsScore: searching 1.1.1.1 in /var/tmp/cins.txt: open /var/tmp/cins.txt: The system cannot find the path specified.

checkip.exe: MaxMind: open /var/tmp/GeoLite2-City.mmdb: The system cannot find the path specified.

Access denied in windows 11

i want to update version in my pc.

i download it with wget(windows) then extract it in previously directory.

PS C:\Portables\Tools> .\checkip.exe
Program 'checkip.exe' failed to run: Access is deniedAt line:1 char:1
+ .\checkip.exe
+ ~~~~~~~~~~~~~.
At line:1 char:1
+ .\checkip.exe
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedException
    + FullyQualifiedErrorId : NativeCommandFailed

i search a clue about wich file are denies but no luck.

i have .checkip.yaml in same directory also i copied it in to my user path. c:\users\yunus.checkip.yaml

do you have any idea how can i run it. ?

Certificate error connecting to ThreadCrowd

$ checkip 1.1.1.1
checkip: ThreadCrowd: Get "https://www.threatcrowd.org/searchApi/v2/ip/report?ip=1.1.1.1": x509: “*.otxb.io” certificate name does not match input
<...SNIP...>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.