An open API service indexing awesome lists of open source software.

https://github.com/jonhadfield/ip-fetcher

A go library and CLI to fetch IP ranges from popular online sources
https://github.com/jonhadfield/ip-fetcher

address aws azure gcp go golang google ips networks oci

Last synced: 4 months ago
JSON representation

A go library and CLI to fetch IP ranges from popular online sources

Awesome Lists containing this project

README

          

# ip-fetcher

[![GoDoc](https://godoc.org/github.com/jonhadfield/ip-fetcher?status.svg)](https://pkg.go.dev/github.com/jonhadfield/ip-fetcher)
[![Go Report Card](https://goreportcard.com/badge/github.com/jonhadfield/ip-fetcher)](https://goreportcard.com/report/github.com/jonhadfield/ip-fetcher)

## about

ip-fetcher is a go library and cli used to retrieve public ip prefixes from popular cloud and hosting providers.
Please raise an issue if you have any issues or suggestions for new providers.

## supported providers

- AbuseIPDB
- AWS (Amazon Web Services)
- Alibaba
- Bingbot
- Cloudflare
- DigitalOcean
- Fastly
- GCP (Google Cloud Platform)
- Google
- Googlebot
- Google Special Crawlers
- Google User-Triggered Fetchers
- MaxMind GeoIP
- Microsoft Azure
- Akamai
- Hetzner
- GitHub
- Linode
- M247
- Scaleway
- Oracle Cloud Infrastructure
- iCloud Private Relay
- OVHcloud
- Vultr
- Zscaler
- Custom URL

## CLI

### install

Download the latest release [here](https://github.com/jonhadfield/ip-fetcher/releases) and then install:

```bash
install /usr/local/bin/ip-fetcher
```
_use: `sudo install` if on linux_

### run

```
ip-fetcher
```
for example:
- output aws prefixes to the console: `ip-fetcher aws --stdout`
- save gcp prefixes to a file: `ip-fetcher gcp --file prefixes.json`
- publish all ranges to a git repository: `ip-fetcher publish`
- set the `PREFIX_FETCHER_LOG` environment variable to change log verbosity
e.g. `PREFIX_FETCHER_LOG=debug ip-fetcher aws --stdout`

## API

The following example uses the GCP (Google Cloud Platform) provider.

### installation
```
go get github.com/jonhadfield/ip-fetcher/providers/gcp
```
### basic usage
```
package main

import (
"fmt"
"github.com/jonhadfield/ip-fetcher/providers/gcp"
)

func main() {
g := gcp.New() // initialise client
doc, err := g.Fetch() // fetch prefixes document
if err != nil {
panic(err)
}

for _, p := range doc.IPv6Prefixes {
fmt.Printf("%s %s %s\n", p.IPv6Prefix.String(), p.Service, p.Scope)
}
}
```