AFFVPS

Bandwagon Host / 搬瓦工 利用API自动切换机房脚本

搬瓦工/Bandwagonhost/双十一特惠款/2G内存/CN2/KVM/40G SSD/年付仅29.88美元
配备三网CN2线路能够自由的切换机房,切换IP地址!
填入优惠码 BWH26FXH3HIQ 即可享受-6.25%的循环优惠, 点击购买 数量有限.

    • 简介

听说 DC8 机房好一点, 但是机房爆满.
有没有足够的耐心去手动点击.
好在搬瓦工提供了便利的API.
利用API可以做很多事情.
可以通过Linux自带的wget调用搬瓦工的API,实在是方便.

需要在搬瓦工机器后台面板中找到 API.
记录VEIDAPI KEY.然后将其填入脚本中.
切换到目标机房后,将会自动停止.

  • 下载
wget --no-check-certificate -qO BWH.sh 'https://moeclub.org/attachment/LinuxShell/BWH.sh' && chmod a+x BWH.sh
  • 设置

自行以下设置项:

veid='1234560'; # VEID
api_key='private_xxxxxxxxxxxxxxxxx'; # API KEY
ToLocation='USCA_8'; # 目标机房代码.
Timeout='150';  # API频率有限制,单位秒.每150秒运行一次.(不建议过低,否则面板报错.)
  • 运行
#前台运行
bash BWH.sh
#后台运行
nohup bash BWH.sh >/dev/null 2>&1 &
    • 预览
#!/bin/bash
 
veid='1234560';
api_key='private_xxxxxxxxxxxxxxxxx';
ToLocation='USCA_8';
Timeout='150';
 
# START
[[ -n "$veid" ]] || exit 1
[[ -n "$api_key" ]] || exit 1
[[ -n "$ToLocation" ]] || exit 1
[[ -n "$Timeout" ]] || exit 1
 
CurrentLocation='';
Token="?veid=${veid}&api_key=${api_key}";
API_URL="https://api.64clouds.com/v1/";
while [[ "$CurrentLocation" != "$ToLocation" ]]; do
  CurrentLocation=$(wget --no-check-certificate -qO- "${API_URL}migrate/getLocations${Token}" |grep -o '"currentLocation":"[^"]*"' |cut -d'"' -f4)
  echo "$(date +"[%Y/%m/%d %H:%M:%S]") ${CurrentLocation}";
  if [ -n "$CurrentLocation" -a "$CurrentLocation" != "$ToLocation" ]; then
    echo -n "${ToLocation}: "
    wget --no-check-certificate -qO- "${API_URL}migrate/start${Token}&location=${ToLocation}" |grep -o '"message":"[^"]*"' |cut -d'"' -f4
  else
    break;
  fi
  sleep ${Timeout};
done

脚本来源:萌咖博客
码字很辛苦,转载请注明来自AFFVPS《Bandwagon Host / 搬瓦工 利用API自动切换机房脚本》

评论