Bandwagon Host用API自动切换机房脚本教程

前言
前两天购买了一个搬瓦工机器,双十一特价款,年付不到30美元,支持支付宝,配备三网CN2线路能够自由的切换机房,切换IP地址!填入优惠码 BWH26FXH3HIQ 即可享受1-6.25%1的循环优惠,点击购买 数量有限!

简介
听说 DC8 机房好一点,但是机房爆满,又没有足够的耐心去手动点击,好在搬瓦工提供了便利的API!利用API可以做很多事情,可以通过Linux自带的wget调用搬瓦工的API,非常方便。需要在搬瓦工机器后台面板中找到 API,记录VEIDAPI KEY,然后将其填入脚本中,切换到目标机房后,将会自动停止。

教程开始(此脚本来自萌咖大佬!)

  • 下载

下载教程到你的VPS:

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

最后修改:2018 年 11 月 12 日
如果觉得我的文章对你有用,请随意赞赏