-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4866eb5
commit c55c936
Showing
16 changed files
with
197 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
function getCfPrefs() { | ||
curl -s "https://api.bgpview.io/asn/${1}/prefixes" | \ | ||
jq -r '.data.ipv4_prefixes[] | select(.description | try test("Cloud(f|F)")) | .parent.prefix' | ||
} | ||
|
||
DB="$(echo -e "$(getCfPrefs "13335")\n$(getCfPrefs "395747")" | sort -u)" | ||
|
||
if [[ "$(echo "${DB}" | wc -l)" != "$(curl -skL "${1}" | wc -l)" ]]; then | ||
echo "${DB}" > db/prefixes.txt | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Update DB | ||
on: | ||
schedule: | ||
- cron: "0 0 * * 0" # at 00:00 on Sunday | ||
workflow_dispatch: | ||
|
||
jobs: | ||
update: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Install dependencies" | ||
run: sudo apt install curl jq -y | ||
|
||
- name: "Check out code" | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: "Update DB..." | ||
id: update | ||
run: | | ||
./.github/scripts/update.sh ${{ secrets.LOCAL_DB }} | ||
echo "::set-output name=changes::$(git status -s | wc -l)" | ||
echo "::set-output name=date::$(date)" | ||
- name: Create Pull Request | ||
if: steps.update.outputs.changes > 0 | ||
uses: peter-evans/create-pull-request@v3 | ||
with: | ||
body: "Automated update CloudFlare IPv4 prefixes data." | ||
branch-suffix: "short-commit-hash" | ||
branch: "update/db" | ||
commit-message: "db: Update DB ${{ steps.update.date }}" | ||
committer: "Dwi Siswanto <me@dw1.io>" | ||
delete-branch: true | ||
reviewers: "dwisiswant0" | ||
title: "db: Update DB ${{ steps.update.date }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cf-check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
builds: | ||
- binary: cf-check | ||
main: main.go | ||
main: . | ||
goos: | ||
- linux | ||
- windows | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import "net" | ||
|
||
func isCloudflare(ip net.IP) bool { | ||
for _, c := range cidrs { | ||
if c == "" { | ||
continue | ||
} | ||
|
||
hosts, err := hosts(c) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
for _, host := range hosts { | ||
if host == ip.String() { | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package db | ||
|
||
import "strings" | ||
|
||
func init() { | ||
Prefs = strings.Split(prefs, "\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package db | ||
|
||
import _ "embed" | ||
|
||
var ( | ||
//go:embed prefixes.txt | ||
prefs string | ||
Prefs []string | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/dwisiswant0/cf-check | ||
|
||
go 1.13 | ||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
) | ||
|
||
func show(host string, ip net.IP, mode bool) { | ||
if mode { | ||
fmt.Println(host) | ||
} else { | ||
fmt.Println(ip) | ||
} | ||
} | ||
|
||
func inc(ip net.IP) { | ||
for j := len(ip) - 1; j >= 0; j-- { | ||
ip[j]++ | ||
if ip[j] > 0 { | ||
break | ||
} | ||
} | ||
} | ||
|
||
func hosts(cidr string) ([]string, error) { | ||
ip, ipnet, err := net.ParseCIDR(cidr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var ips []string | ||
for ip := ip.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) { | ||
ips = append(ips, ip.String()) | ||
} | ||
|
||
lenIPs := len(ips) | ||
switch { | ||
case lenIPs < 2: | ||
return ips, nil | ||
default: | ||
return ips[1 : len(ips)-1], nil | ||
} | ||
} | ||
|
||
func isStdin() bool { | ||
f, e := os.Stdin.Stat() | ||
if e != nil { | ||
return false | ||
} | ||
|
||
if f.Mode()&os.ModeNamedPipe == 0 { | ||
return false | ||
} | ||
|
||
return true | ||
} |
Oops, something went wrong.