diff --git a/myip.sh b/myip.sh index e17b6e3..46b0d26 100755 --- a/myip.sh +++ b/myip.sh @@ -9,4 +9,4 @@ fi echo Public IP: `curl -s ifconfig.me` echo -curl ipinfo.io \ No newline at end of file +net.sh diff --git a/net.sh b/net.sh new file mode 100644 index 0000000..17bddb0 --- /dev/null +++ b/net.sh @@ -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 diff --git a/proxy.sh b/proxy.sh index 61e7b40..feb44e6 100755 --- a/proxy.sh +++ b/proxy.sh @@ -41,6 +41,4 @@ echo all_proxy=$all_proxy echo http_proxy=$http_proxy echo https_proxy=$https_proxy -# ip.gs, ip.sb, ipinfo.io -curl ipinfo.io -echo " " +net.sh diff --git a/ssh.sh b/ssh.sh index 5c0803f..a53620f 100755 --- a/ssh.sh +++ b/ssh.sh @@ -19,6 +19,10 @@ if [[ ! -f "$SETTINGS_FILE" ]]; then fi # 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")) hosts=($(jq -r '.["sshfs.configs"][] | .host' "$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")) passwords=($(jq -r '.["sshfs.configs"][] | .password' "$SETTINGS_FILE")) privateKeyPaths=($(jq -r '.["sshfs.configs"][] | .privateKeyPath' "$SETTINGS_FILE")) +IFS=$oldIFS -options=() prefixes=() for i in "${!labels[@]}"; do - option=$(echo "${labels[$i]}" | sed 's/[^[:alnum:]].*//') # 提取前几个字母和数字 - options+=("$option: ${labels[$i]}") # 去掉序号,保留前缀和完整label - prefixes+=("$option") # 保存前缀 + option=$(echo "${labels[$i]}" | sed 's/[^[:alnum:]].*//') # 提取前缀(前导字母数字) + prefixes+=("$option") done # Check if a command-line argument is provided @@ -40,16 +43,26 @@ if [ "$1" != "" ]; then # 如果提供了参数,则直接使用这个前缀 host_to_ssh=$1 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 - # Display options without numbers - for opt in "${options[@]}"; do - echo "$opt" + # 对齐前缀列:按最长前缀宽度填充 + maxlen=0 + 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 echo - read -p "请输入要连接的主机前缀: " host_to_ssh + read -p "请输入要连接的主机前缀 (直接回车退出): " host_to_ssh + # 空输入直接退出(空前缀会误匹配到错乱的数组项,直接拦截) + if [ -z "$host_to_ssh" ]; then + echo "已退出。" + exit 0 + fi fi echo