mirror of
https://github.com/gaoyifan/china-operator-ip.git
synced 2025-12-16 06:13:15 +08:00
refact shell script
* fix wget save to a wrong file name with a same name file * beautify log format * print asn on log * modify/add DEBUG, SKIP_DATA_PREPARATION environment variables
This commit is contained in:
34
common.sh
Executable file
34
common.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
[[ $DEBUG == true ]] && set -x
|
||||
|
||||
log_info(){
|
||||
>&2 echo "INFO>" $@
|
||||
}
|
||||
|
||||
get_asn(){
|
||||
local CONF_FILE=$1
|
||||
unset PATTERN
|
||||
unset COUNTRY
|
||||
source $CONF_FILE
|
||||
grep -P "${COUNTRY}\$" asnames.txt |
|
||||
grep -Pi "$PATTERN" |
|
||||
awk '{print $1}' |
|
||||
while read ASN; do
|
||||
ASN=${ASN#AS}
|
||||
if grep '\.' <(echo $ASN) > /dev/null; then
|
||||
ASN_HIGH=${ASN%.*}
|
||||
ASN_LOW=${ASN#*.}
|
||||
ASN=$((ASN_HIGH * 65536 + ASN_LOW))
|
||||
fi
|
||||
echo $ASN
|
||||
done
|
||||
}
|
||||
|
||||
prepare_data(){
|
||||
wget http://bgp.potaroo.net/as1221/asnames.txt -O asnames.txt
|
||||
wget http://archive.routeviews.org/dnszones/rib.bz2 -O rib.bz2
|
||||
log_info "runing bgpdump ..."
|
||||
docker run -it --rm -v `pwd`:/bgpdump -w /bgpdump gaoyifan/bgpdump bgpdump -m -O rib.txt rib.bz2
|
||||
log_info "done"
|
||||
}
|
||||
Reference in New Issue
Block a user