-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilter_generate.sh
51 lines (40 loc) · 986 Bytes
/
filter_generate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Lambda-IX Member List
i=0
total=`expr $(curl https://lambda-ix.net/members.json | jq length) - 2`
member_list="https://lambda-ix.net/members.json"
# Generate Filter
while [ $i -lt $total ]
do
# ASN
ASN=$(curl https://lambda-ix.net/members.json | jq '.['$i'].asn')
ASN=${ASN//'"'/}
# AS-SET
AS_SET=$(curl https://www.peeringdb.com/api/as_set/$ASN | jq '.data[0]["'$ASN'"]')
AS_SET=${AS_SET//'"'/}
# Print
echo $ASN
AS_SET=${AS_SET#*::}
if [ ! $AS_SET ];
then
AS_SET="AS"$ASN
fi
echo $AS_SET
# Generate filter
filter_v4=$(bgpq3 -4l "define AS"$ASN"_v4" $AS_SET -R 24 -b)
filter_v6=$(bgpq3 -6l "define AS"$ASN"_v6" $AS_SET -R 48 -b)
if [[ ! $filter_v4 ]];
then
filter_v4="define AS"$ASN"_v4 = [ 149.112.26.0/24 ];"
fi
if [[ ! $filter_v6 ]];
then
filter_v6="define AS"$ASN"_v6 = [ 2a0f:607:1070::/48 ];"
fi
cat << EOF > /etc/bird/filters/"AS"$ASN"_v4"
$filter_v4
EOF
cat << EOF > /etc/bird/filters/"AS"$ASN"_v6"
$filter_v6
EOF
i=`expr $i + 1`
done