detest my ip's location

This commit is contained in:
luk
2026-10-14 09:44:42 +08:00
parent 1857f86ff2
commit 2abbc95a8b
4 changed files with 31 additions and 13 deletions
+1 -1
View File
@@ -9,4 +9,4 @@ fi
echo Public IP: `curl -s ifconfig.me` echo Public IP: `curl -s ifconfig.me`
echo echo
curl ipinfo.io net.sh
+7
View File
@@ -0,0 +1,7 @@
echo https://ipinfo.io/country == $(curl -s https://ipinfo.io/country) # 返回国家代码,例如 CN, DE, US
echo https://myip.ipip.net == $(curl -s https://myip.ipip.net) # 国内站应显示无锡/电信(直连)
echo https://ipinfo.io/json ==
curl -s https://ipinfo.io/json # 详情:IP、城市、组织
# curl ipinfo.io
echo
+1 -3
View File
@@ -41,6 +41,4 @@ echo all_proxy=$all_proxy
echo http_proxy=$http_proxy echo http_proxy=$http_proxy
echo https_proxy=$https_proxy echo https_proxy=$https_proxy
# ip.gs, ip.sb, ipinfo.io net.sh
curl ipinfo.io
echo " "
+22 -9
View File
@@ -19,6 +19,10 @@ if [[ ! -f "$SETTINGS_FILE" ]]; then
fi fi
# Parse the JSON to get labels and corresponding details # Parse the JSON to get labels and corresponding details
# 临时把 IFS 设为换行,让 =($(...)) 只按行拆分、保留 label 内部空格,
# 避免默认 IFS(空格) 拆散含空格的 label,导致每台显示两行、labels/hosts 错位
oldIFS=$IFS
IFS=$'\n'
labels=($(jq -r '.["sshfs.configs"][] | .label' "$SETTINGS_FILE")) labels=($(jq -r '.["sshfs.configs"][] | .label' "$SETTINGS_FILE"))
hosts=($(jq -r '.["sshfs.configs"][] | .host' "$SETTINGS_FILE")) hosts=($(jq -r '.["sshfs.configs"][] | .host' "$SETTINGS_FILE"))
ports=($(jq -r '.["sshfs.configs"][] | .port' "$SETTINGS_FILE")) ports=($(jq -r '.["sshfs.configs"][] | .port' "$SETTINGS_FILE"))
@@ -26,13 +30,12 @@ names=($(jq -r '.["sshfs.configs"][] | .name' "$SETTINGS_FILE"))
usernames=($(jq -r '.["sshfs.configs"][] | .username' "$SETTINGS_FILE")) usernames=($(jq -r '.["sshfs.configs"][] | .username' "$SETTINGS_FILE"))
passwords=($(jq -r '.["sshfs.configs"][] | .password' "$SETTINGS_FILE")) passwords=($(jq -r '.["sshfs.configs"][] | .password' "$SETTINGS_FILE"))
privateKeyPaths=($(jq -r '.["sshfs.configs"][] | .privateKeyPath' "$SETTINGS_FILE")) privateKeyPaths=($(jq -r '.["sshfs.configs"][] | .privateKeyPath' "$SETTINGS_FILE"))
IFS=$oldIFS
options=()
prefixes=() prefixes=()
for i in "${!labels[@]}"; do for i in "${!labels[@]}"; do
option=$(echo "${labels[$i]}" | sed 's/[^[:alnum:]].*//') # 提取前几个字母和数字 option=$(echo "${labels[$i]}" | sed 's/[^[:alnum:]].*//') # 提取前缀(前导字母数字)
options+=("$option: ${labels[$i]}") # 去掉序号,保留前缀和完整label prefixes+=("$option")
prefixes+=("$option") # 保存前缀
done done
# Check if a command-line argument is provided # Check if a command-line argument is provided
@@ -40,16 +43,26 @@ if [ "$1" != "" ]; then
# 如果提供了参数,则直接使用这个前缀 # 如果提供了参数,则直接使用这个前缀
host_to_ssh=$1 host_to_ssh=$1
else else
echo "Select a target to connect via SSH, or press 0 to exit:" echo "Select a target to connect via SSH (Enter to exit):"
echo echo
# Display options without numbers # 对齐前缀列:按最长前缀宽度填充
for opt in "${options[@]}"; do maxlen=0
echo "$opt" for p in "${prefixes[@]}"; do
[ ${#p} -gt $maxlen ] && maxlen=${#p}
done
for i in "${!labels[@]}"; do
printf "%-*s: %s\n" "$maxlen" "${prefixes[$i]}" "${labels[$i]}"
done done
echo echo
read -p "请输入要连接的主机前缀: " host_to_ssh read -p "请输入要连接的主机前缀 (直接回车退出): " host_to_ssh
# 空输入直接退出(空前缀会误匹配到错乱的数组项,直接拦截)
if [ -z "$host_to_ssh" ]; then
echo "已退出。"
exit 0
fi
fi fi
echo echo