From 0a836c3c2788d4ae7565ff8549c31a48cd52bc28 Mon Sep 17 00:00:00 2001 From: Darren <27513732@qq.com> Date: Thu, 14 Jul 2022 09:25:01 +0800 Subject: [PATCH] Create get_ip.sh --- scripts/get_ip.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 scripts/get_ip.sh diff --git a/scripts/get_ip.sh b/scripts/get_ip.sh new file mode 100644 index 00000000..c508a60d --- /dev/null +++ b/scripts/get_ip.sh @@ -0,0 +1,41 @@ +#!/bin/bash +url_list=( + api.ipify.org + bot.whatismyipaddress.com + icanhazip.com + ifconfig.co + ident.me + ifconfig.me + icanhazip.com + ipecho.net/plain + ipinfo.io/ip + ip.sb + whatismyip.akamai.com + inet-ip.info +) + +curl_ip(){ + curl --connect-timeout 1 -m 2 $1 2>/dev/null + return $? +} + +debug(){ + for x in ${url_list[*]} + do + curl_ip $x + done +} + +print_ip(){ + for n in ${url_list[*]} + do + public_ip=`curl_ip $n` + check_ip=`echo $public_ip | awk -F"." '{print NF}'` + if [ ! -z "$public_ip" -a $check_ip -eq "4" ]; then + echo $public_ip + exit 0 + fi + done +} +#debug +print_ip