You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

  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. TARGET_IPSET='wan'
  6. TARGET_ASN='2906'
  7. TARGET_FNAME="/var/vpn-policy-routing_tmp_AS${TARGET_ASN}"
  8. #DB_SOURCE='ipinfo.io'
  9. #DB_SOURCE='api.hackertarget.com'
  10. DB_SOURCE='api.bgpview.io'
  11. _ret=1
  12. if [ ! -s "$TARGET_FNAME" ]; then
  13. if [ "$DB_SOURCE" = "ipinfo.io" ]; then
  14. TARGET_URL="https://ipinfo.io/AS${TARGET_ASN}"
  15. curl "$TARGET_URL" 2>/dev/null | grep -E "a href.*${TARGET_ASN}\/" | grep -v ":" | sed "s/^.*<a href=\"\/AS${TARGET_ASN}\///; s/\" >//" > "$TARGET_FNAME"
  16. fi
  17. if [ "$DB_SOURCE" = "api.hackertarget.com" ]; then
  18. TARGET_URL="https://api.hackertarget.com/aslookup/?q=AS${TARGET_ASN}"
  19. curl "$TARGET_URL" 2>/dev/null | sed '1d' > "$TARGET_FNAME"
  20. fi
  21. if [ "$DB_SOURCE" = "api.bgpview.io" ]; then
  22. TARGET_URL="https://api.bgpview.io/asn/${TARGET_ASN}/prefixes"
  23. curl -s "$TARGET_URL" 2>/dev/null | jsonfilter -e '@.data.ipv4_prefixes[*].prefix' > "$TARGET_FNAME"
  24. fi
  25. fi
  26. if [ -s "$TARGET_FNAME" ]; then
  27. awk -v ipset="$TARGET_IPSET" '{print "add " ipset " " $1}' "$TARGET_FNAME" | ipset restore -! && _ret=0
  28. fi
  29. rm -f "$TARGET_FNAME"
  30. return $_ret