Skip to content

danfaizer/aws-ip-check

Repository files navigation

Build Status codecov Go Report Card GoDoc Github Action

aws-ip-check

aws-ip-check provides a go library and a command line tool to check if an IP address belongs to Amazon Web Service (AWS) infrastructure or not.

This tool relies on public AWS IP range file.

Command line tool

Make sure you have a working go environment.

To install aws-ip-check cli run:

go get -x github.com/danfaizer/aws-ip-check/cmd/aws-ip-check

Usage

$ ~/go/bin/aws-ip-check -help

usage: aws-ip-check [flags] ip
  -cache string
      File path where to store cache.
  -extra
      Provide extra info of the IP if belongs to AWS.
  -format string
      Output format for the IP extra info. (default "text")
  -ttl int
      AWS soruce IP data cache TTL in seconds. 0 means infinite.

aws-ip-check will return the following exit statuses:

status description
0 IP belongs to AWS IP range
1 IP does NOT belong to AWS IP range
2 aws-ip-check execution error

Example

aws-ip-check 192.168.0.1
echo $?
1

aws-ip-check $(host console.aws.amazon.com | tail -1 | awk '{print $NF}')
echo $?
0

Library

import (
    "github.com/danfaizer/aws-ip-check/pkg/check"
)

func CheckAWSIP(ip string) (bool, error) {
  c, err := check.NewClient(&check.Options{})
  if err != nil {
    return false, err
  }

  found, _, err := c.Check("192.168.0.1")
  return found, err
}

Docker

Build the docker image:

docker build . -t aws-check-ip

Run the docker image:

docker run --rm aws-check-ip 192.168.0.1
echo $?
1

docker run --rm aws-check-ip $(host console.aws.amazon.com | tail -1 | awk '{print $NF}')
echo $?
0

About

Check if IP address is part of AWS infrastructure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published