Skip to content

Instantly share code, notes, and snippets.

@aachyee
Forked from Hayao0819/vpngate_api
Last active February 12, 2024 22:50
Show Gist options
  • Select an option

  • Save aachyee/22a4cf9a5954f77fb4e3f28c68beee69 to your computer and use it in GitHub Desktop.

Select an option

Save aachyee/22a4cf9a5954f77fb4e3f28c68beee69 to your computer and use it in GitHub Desktop.
VPN Gateのサーバリストを取得してBashの配列にするスクリプト
#!/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}" | tr -d '\r')"
# 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 < <(sed -n '/^#HostName,/p' <<<${CSV} | tr -d '#' | tr ',' '\n' )
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 < <(sed '/^[*#]/d' <<<${CSV} | sed 's|,,|, ,|g')
# 出力実装例
# 配列にそれぞれの値が入っています
for _count in $(seq 0 $((${#HostName[@]} - 1))); do
OpenVPN_ConfigData=$(base64 -d 2>/dev/null <<<${OpenVPN_ConfigData_Base64[_count]} | tr -d '\r' | sed '/^[#;]/d')
proto=$(grep -E '^proto ' <<<${OpenVPN_ConfigData} | cut -d\ -f2)
port=$(grep -E '^remote ' <<<${OpenVPN_ConfigData} | cut -d\ -f3)
echo "${HostName[_count]} ${IP[_count]} ${proto}/${port} ${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