openwrt polymarket without additoional packages
This commit is contained in:
82
linux/openwrt/starlink-policy-route.sh
Normal file
82
linux/openwrt/starlink-policy-route.sh
Normal file
@@ -0,0 +1,82 @@
|
||||
#!/bin/sh
|
||||
# Policy routing: send traffic to specified domains via Starlink (wan2).
|
||||
# No mwan3 required. Uses ip rule + custom table. Run on OpenWrt.
|
||||
# Usage: run from hotplug (wan2 ifup) or manually after wan2 is up.
|
||||
# Requires: ip, resolveip, ubus, jsonfilter (all default on OpenWrt).
|
||||
|
||||
TABLE_ID=100
|
||||
WAN2_IF=wan2
|
||||
DOMAINS="polymarket.com www.polymarket.com"
|
||||
|
||||
# Optional: set IPs manually if resolveip fails (e.g. no DNS yet). Space-separated.
|
||||
# POLYMARKET_IPS="1.2.3.4 5.6.7.8"
|
||||
POLYMARKET_IPS=""
|
||||
|
||||
get_wan2_gw() {
|
||||
local status
|
||||
status=$(ubus call network.interface."$WAN2_IF" status 2>/dev/null) || return 1
|
||||
echo "$status" | jsonfilter -e '@.route[0].nexthop' 2>/dev/null
|
||||
}
|
||||
|
||||
get_wan2_dev() {
|
||||
local status
|
||||
status=$(ubus call network.interface."$WAN2_IF" status 2>/dev/null) || return 1
|
||||
echo "$status" | jsonfilter -e '@.device' 2>/dev/null
|
||||
}
|
||||
|
||||
resolve_domains() {
|
||||
if [ -n "$POLYMARKET_IPS" ]; then
|
||||
echo "$POLYMARKET_IPS"
|
||||
return
|
||||
fi
|
||||
local list=""
|
||||
for d in $DOMAINS; do
|
||||
for ip in $(resolveip -4 -t 2 "$d" 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'); do
|
||||
[ -n "$ip" ] && list="$list $ip"
|
||||
done
|
||||
done
|
||||
echo "$list" | tr ' ' '\n' | sort -u | tr '\n' ' '
|
||||
}
|
||||
|
||||
do_setup() {
|
||||
local gw dev ips ip
|
||||
gw=$(get_wan2_gw)
|
||||
dev=$(get_wan2_dev)
|
||||
if [ -z "$gw" ] || [ -z "$dev" ]; then
|
||||
logger -t starlink-policy "wan2 not ready (gw=$gw dev=$dev)"
|
||||
return 1
|
||||
fi
|
||||
ips=$(resolve_domains)
|
||||
if [ -z "$ips" ]; then
|
||||
logger -t starlink-policy "No IPs resolved for: $DOMAINS. Set POLYMARKET_IPS in script or check DNS."
|
||||
return 1
|
||||
fi
|
||||
for ip in $ips; do
|
||||
ip rule del to "$ip" table $TABLE_ID 2>/dev/null
|
||||
done
|
||||
ip route flush table $TABLE_ID 2>/dev/null
|
||||
ip route add default via "$gw" dev "$dev" table $TABLE_ID
|
||||
for ip in $ips; do
|
||||
ip rule add to "$ip" table $TABLE_ID
|
||||
done
|
||||
logger -t starlink-policy "Routes via wan2 ($dev): $ips"
|
||||
}
|
||||
|
||||
do_remove() {
|
||||
local ips ip
|
||||
ips=$(resolve_domains)
|
||||
for ip in $ips; do
|
||||
ip rule del to "$ip" table $TABLE_ID 2>/dev/null
|
||||
done
|
||||
ip route flush table $TABLE_ID 2>/dev/null
|
||||
logger -t starlink-policy "Removed policy routes for table $TABLE_ID"
|
||||
}
|
||||
|
||||
case "${1:-setup}" in
|
||||
setup) do_setup ;;
|
||||
remove) do_remove ;;
|
||||
*)
|
||||
echo "Usage: $0 [setup|remove]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user