Merge pull request #16078 from ja-pa/fix-email
[feed/packages.git] / net / vpn-policy-routing / files / vpn-policy-routing.netflix.user
1 #!/bin/sh
2 # This file is heavily based on code from https://github.com/Xentrk/netflix-vpn-bypass/blob/master/IPSET_Netflix.sh
3 # Credits to https://forum.openwrt.org/u/dscpl for api.hackertarget.com code.
4 # Credits to https://github.com/kkeker and https://github.com/tophirsch for api.bgpview.io code.
5
6 TARGET_IPSET='wan'
7 TARGET_ASN='2906'
8 TARGET_FNAME="/var/vpn-policy-routing_tmp_AS${TARGET_ASN}"
9 #DB_SOURCE='ipinfo.io'
10 #DB_SOURCE='api.hackertarget.com'
11 DB_SOURCE='api.bgpview.io'
12
13 _ret=1
14
15 if [ ! -s "$TARGET_FNAME" ]; then
16 if [ "$DB_SOURCE" = "ipinfo.io" ]; then
17 TARGET_URL="https://ipinfo.io/AS${TARGET_ASN}"
18 uclient-fetch --no-check-certificate -qO- "$TARGET_URL" 2>/dev/null | grep -E "a href.*${TARGET_ASN}\/" | grep -v ":" | sed "s/^.*<a href=\"\/AS${TARGET_ASN}\///; s/\" >//" > "$TARGET_FNAME"
19 fi
20
21 if [ "$DB_SOURCE" = "api.hackertarget.com" ]; then
22 TARGET_URL="https://api.hackertarget.com/aslookup/?q=AS${TARGET_ASN}"
23 uclient-fetch --no-check-certificate -qO- "$TARGET_URL" 2>/dev/null | sed '1d' > "$TARGET_FNAME"
24 fi
25
26 if [ "$DB_SOURCE" = "api.bgpview.io" ]; then
27 TARGET_URL="https://api.bgpview.io/asn/${TARGET_ASN}/prefixes"
28 uclient-fetch --no-check-certificate -qO- "$TARGET_URL" 2>/dev/null | jsonfilter -e '@.data.ipv4_prefixes[*].prefix' > "$TARGET_FNAME"
29 fi
30 fi
31
32 if [ -s "$TARGET_FNAME" ]; then
33 awk -v ipset="$TARGET_IPSET" '{print "add " ipset " " $1}' "$TARGET_FNAME" | ipset restore -! && _ret=0
34 fi
35 rm -f "$TARGET_FNAME"
36
37 return $_ret