Last active
February 12, 2024 22:06
-
-
Save Hayao0819/250421e419290147b5f5f506758adafd to your computer and use it in GitHub Desktop.
VPN Gateのサーバリストを取得してBashの配列にするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 設定 | |
API="http://www.vpngate.net/api/iphone/" | |
msg_info(){ echo -e "${*}"; } | |
# APIで取得したリストを読み込み | |
#msg_info "Loading the list of server ..." | |
CSV="$(curl -sL "${API}")" | |
# CSVのフォーマットを取得 | |
# HostName IP Score Ping Speed CountryLong CountryShort NumVpnSessions | |
# Uptime TotalUsers TotalTraffic LogType Operator Message OpenVPN_ConfigData_Base64 | |
while read -r _format; do | |
CSV_FORMAT+=("${_format}") | |
done < <(echo "${CSV}" | sed -n "2P" | tr -d "#" | tr "," "\n" | tr -d "\r") | |
while read -r line; do | |
for _count in $(seq 1 ${#CSV_FORMAT[@]}); do | |
_name=$(printf "%s" "${CSV_FORMAT[$(( ${_count} - 1 ))]}") | |
_value="$(printf "%s" "${line}" | cut -d ',' -f "$(( ${_count} + 0))")" | |
eval "${_name}+=(\"${_value}\")" | |
done | |
done < <(printf "%s\n" "${CSV}" | tail -n +3 | head -n -3 | sed "s|,,|, ,|g") | |
# 出力実装例 | |
# 配列にそれぞれの値が入っています | |
for _count in $(seq 0 $((${#HostName[@]} - 1))); do | |
echo "${HostName[_count]} ${IP[_count]} ${Score[_count]} ${Ping[_count]} ${Speed[_count]} ${CountryLong[_count]} ${CountryShort[_count]} ${NumVpnSessions[_count]} ${Uptime[_count]} ${TotalUsers[_count]} ${TotalTraffic[_count]} ${LogType[_count]}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment