forked from borestad/blocklist-abuseipdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate
executable file
·54 lines (41 loc) · 1.61 KB
/
aggregate
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
52
53
54
#!/usr/bin/env bash
LATEST="abuseipdb-s100.ipv4"
aggregate() {
local HOURS=$1
local OUTPUT=$2
TEMPFILE=$(mktemp)
cat $LATEST >> $TEMPFILE
for commit in $(git log --format=format:%H --since="$HOURS hours ago" $LATEST); do
let "i++"
git show $commit:$LATEST >> $TEMPFILE
# Optimize in chunks to ensure the tempfile doesn't become HUGE
if [[ "$i%100" -eq "0" ]]; then
iprange --print-single-ips $TEMPFILE >| "$TEMPFILE-tmp"
mv "$TEMPFILE-tmp" $TEMPFILE
fi
done
iprange --print-single-ips $TEMPFILE >| $OUTPUT
echo "$OUTPUT (`wc -l < $OUTPUT` ip)"
}
update-stats() {
echo "✨ Update footer"
# Delete everything below placeholder
sed -i '/FOOTER-PLACEHOLDER/q' README.md
update=$(date -u '+%Y-%m-%d - %H:%M:%S')
echo "Updated every 5 hours<br>" >> README.md
echo "Last update: \`$update\`" >> README.md
echo '```' >> README.md
find . -mindepth 1 -maxdepth 1 -iname '*.ipset' -print0 | sort -zV | xargs -I {} -0 sh -c 'name=$(basename {}); echo "$name ($(wc -l < $name) ip)"' >> README.md
echo '```' >> README.md
}
aggregate $(( 24 + 1 )) "abuseipdb-s100-1d.ipset" &
aggregate $(( 24 * 2 + 1 )) "abuseipdb-s100-2d.ipset" &
aggregate $(( 24 * 3 + 1 )) "abuseipdb-s100-3d.ipset" &
aggregate $(( 24 * 7 + 1 )) "abuseipdb-s100-7d.ipset" &
aggregate $(( 24 * 30 + 1 )) "abuseipdb-s100-30d.ipset" &
aggregate $(( 24 * 60 + 1 )) "abuseipdb-s100-60d.ipset" &
aggregate $(( 24 * 90 + 1 )) "abuseipdb-s100-90d.ipset" &
aggregate $(( 24 * 120 + 1 )) "abuseipdb-s100-120d.ipset" &
aggregate $(( 24 * 9999 )) "abuseipdb-s100-all.ipset" &
wait
update-stats