Skip to content

Commit 51b6915

Browse files
committed
v4.ident.me is down, add alternatives
1 parent 8b82985 commit 51b6915

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

op-node-entrypoint

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
#!/bin/bash
22
set -eu
33

4+
get_public_ip() {
5+
# Define a list of HTTP-based providers
6+
local PROVIDERS=(
7+
"http://ifconfig.me"
8+
"http://api.ipify.org"
9+
"http://ipecho.net/plain"
10+
"http://v4.ident.me"
11+
)
12+
# Iterate through the providers until an IP is found or the list is exhausted
13+
for provider in "${PROVIDERS[@]}"; do
14+
local IP
15+
IP=$(curl -s "$provider")
16+
# Check if IP contains a valid format (simple regex for an IPv4 address)
17+
if [[ $IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
18+
echo "$IP"
19+
return 0
20+
fi
21+
done
22+
return 1
23+
}
24+
425
if [[ -z "$OP_NODE_NETWORK" ]]; then
5-
echo "expected OP_NODE_NETWORK to be set" 1>&2
6-
exit 1
26+
echo "expected OP_NODE_NETWORK to be set" 1>&2
27+
exit 1
728
fi
829

930
# wait until local geth comes up (authed so will return 401 without token)
@@ -13,7 +34,12 @@ until [ "$(curl -s -w '%{http_code}' -o /dev/null "${OP_NODE_L2_ENGINE_RPC/ws/ht
1334
done
1435

1536
# public-facing P2P node, advertise public IP address
16-
PUBLIC_IP=$(curl -s v4.ident.me)
37+
if PUBLIC_IP=$(get_public_ip); then
38+
echo "fetched public IP is: $PUBLIC_IP"
39+
else
40+
echo "Could not retrieve public IP."
41+
exit 8
42+
fi
1743
export OP_NODE_P2P_ADVERTISE_IP=$PUBLIC_IP
1844

1945
echo "$OP_NODE_L2_ENGINE_AUTH_RAW" > "$OP_NODE_L2_ENGINE_AUTH"

0 commit comments

Comments
 (0)