Skip to content

Commit

Permalink
Use GitHub Actions to update datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
kinosang committed Sep 25, 2021
1 parent abd1fd7 commit 6d901de
Show file tree
Hide file tree
Showing 9 changed files with 638 additions and 1,154 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build Dataset

on:
push:
branches:
- master

schedule:
- cron: "0 0 * * *"

jobs:
build-ipasn:
name: Build IPASN
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2

- name: Download datasource
run: |
curl https://iptoasn.com/data/ip2asn-combined.tsv.gz | gunzip -c | tee data/ip2asn.tsv
- name: Build dataset
run: |
go run cmd/ipasn/ipasn.go
- uses: eine/tip@master
with:
tag: "nightly"
token: ${{ github.token }}
files: |
./data/ipasn.mmdb
440 changes: 18 additions & 422 deletions LICENSE

Large diffs are not rendered by default.

427 changes: 427 additions & 0 deletions LICENSE-CC

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# OpenData

### Datacenter ASN list
[datacenter.tsv](datacenter.tsv)
## Datasets

A TAB-separated list of ASNs known to belong to cloud, managed hosting, and colo facilities.
### IPASN

**Format:**
`as_number` `as_description`
IP-to-ASN map.

### License
#### MMDB

[CC BY-SA 4.0](LICENSE)
[ipasn.mmdb](releases/latest/download/ipasn.mmdb)

**Fields:**
`asn` `name`

#### Sources

- [IPtoASN](https://iptoasn.com/)

## License

Codes are licensed under [The MIT License](LICENSE).

Datasets are licensed under [CC BY-SA 4.0](LICENSE-CC).
79 changes: 79 additions & 0 deletions cmd/ipasn/ipasn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2021 JoyMoe Interactive Entertainment Limited
// SPDX-License-Identifier: MIT

package main

import (
"encoding/csv"
"io"
"log"
"net"
"os"
"strconv"

"github.com/maxmind/mmdbwriter"
"github.com/maxmind/mmdbwriter/mmdbtype"
)

func main() {
writer, err := mmdbwriter.New(mmdbwriter.Options{
RecordSize: 24,
})
if err != nil {
log.Fatal(err)
}

f, err := os.Open("data/ip2asn.tsv")
if err != nil {
log.Fatal(err)
}
defer f.Close()

r := csv.NewReader(f)
r.Comma = '\t'
r.LazyQuotes = true

for {
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
log.Println(err)
continue
}

start := net.ParseIP(record[0])
end := net.ParseIP(record[1])
asn, err := strconv.ParseUint(record[2], 10, 32)

if start == nil || end == nil || err != nil {
log.Printf("Invalid IP range: %s - %s %s", record[0], record[1], record[2])
continue
}

if asn == 0 {
continue
}

name := record[4]

if err := writer.InsertRange(start, end, mmdbtype.Map{
"asn": mmdbtype.Uint32(asn),
"name": mmdbtype.String(name),
}); err != nil {
log.Printf("%s - %s %s", record[0], record[1], record[2])
log.Println(err)
continue
}
}

fh, err := os.Create("data/ipasn.mmdb")
if err != nil {
log.Fatal(err)
}
_, err = writer.WriteTo(fh)
if err != nil {
log.Fatal(err)
}
}
2 changes: 2 additions & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Loading

0 comments on commit 6d901de

Please sign in to comment.