搬瓦工秒变动态 ip (伪)

众所周知,搬瓦工可以在后台更换机房达到更换 ip 的目的,且更换机房系统不会被改(不保证数据不丢失的可能)。重要的是,搬瓦工还提供了十分方便的 API ,可以利用 API 来更换机房,再通过 cloudflare 的 API 实现动态域名解析,达到动态 ip 的效果(大雾。

然后就写出了一个渣渣的脚本,勿喷。

#!/bin/bash
# 配合 crontab 食用更佳!
bwh() { # 登陆搬瓦工后台获取相关 API 参数
    Location=(USCA_FMT USCA_3 USCA_8)            # 机房预设
    bwh_id=897252                                # API VEID
    bwh_key=private_sWv1hisMg5hhEI5V5T0GnR8a     # API KEY
    cf
}

cf() { # 登陆 cloudflare 后台获取相关 API 参数
    cf_key=1b1782dc5469d3c3791259045355a775896 # Global API Key
    [email protected]                        # 邮箱
    ZoneID=21094897a47f1t522a031668c7d15d      # Zone ID 

    # 通过这条命令获取以下信息(先解析域名):curl -X GET "https://api.cloudflare.com/client/v4/zones/${ZoneID}/dns_records" -H "X-Auth-Email:${cf_mail}" -H "X-Auth-Key:${cf_key}" -H "Content-Type: application/json"
    dns_id=0bb79d908fbb3239d27c4bbc64c4af      # "id"
    domain_name=feaui.com                      # "name"
    CDN=true                                   # true 开启 cdn,false 为不开启
    GetNewLocation
}

end() {
    DATE=`date +%Y-%m-%d`
    echo "ip:${new_ip}/DATE:$DATE" >> $(cd `dirname $0`; pwd)/ip.txt
    exit 0
}
UpdateDNS() {
    updateDNS_log=`curl -X PUT "https://api.cloudflare.com/client/v4/zones/${ZoneID}/dns_records/${dns_id1}" \
    -H "X-Auth-Email: ${cf_mail}" \
    -H "X-Auth-Key: ${cf_key}" \
    -H "Content-Type: application/json" \
    --data '{"type":"A","name":"'${domain_name}'","content":"'${new_ip}'","ttl":180,"proxied":false}'`
    echo $updateDNS_log    
    end
}

check_ip() {
    IP=$1
    VALID_CHECK=$(echo $IP|awk -F. '$1<=255&&$2<=255&&$3<=255&&$4<=255{print "yes"}')
    if echo $IP|grep -E "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$">/dev/null; then
        if [ ${VALID_CHECK:-no} == "yes" ]; then
            UpdateDNS
        else
            GetNewLocation
        fi
    else
        GetNewLocation
    fi
}

GetNewIp() {
    new_ip=`expr "$New_DCinfo" : '.*\[\(.*\)\]' | sed -n -e 's/"//gp'`

    echo $new_ip
    sleep 3s

    check_ip $new_ip
}

CheckStatus() {
    if [[ $New_DCinfo =~ "734104" ]];then
        echo "$New_DCinfo"  
        sleep 10m
        GetNewLocation
    else
        GetNewIp
    fi
}

MigrateDC() {
    info=`wget -qO- "https://api.64clouds.com/v1/migrate/getLocations?&veid=${bwh_id}&api_key=${bwh_key}"`
    currentLocation=(`expr "$info" : '.*\[\(.*\)\]' | sed -n -e 's/"//gp' | sed 's/,/ /g'`)

    echo "current Location:$currentLocation"
    sleep 3s

    if [ "$new_location" = "$currentLocation" ] ; then
        sleep 10s
        GetNewLocation
    fi

    New_DCinfo=`wget -qO- "https://api.64clouds.com/v1/migrate/start?location=${new_location}&veid=${bwh_id}&api_key=${bwh_key}"`
    CheckStatus
}

GetNewLocation() {
    clear
    echo && echo -e "\033[41;36m 请务必仔细阅读相关注释后再运行此脚本,本人不对此脚本运行后所产生的后果负责! \033[0m" && echo && exit 0 # 删除本行后运行
    sum=${#Location[@]}
    num=`echo $(($RANDOM%${sum}))`
    new_location=`echo ${Location[$num]}`
    echo "new location:$new_location"
    MigrateDC
}
bwh

评论列表

  1. 绅士 绅士

    挺不错的哈!

  2. 云武 云武

    你的网站被墙了,发现吗?

    1. 我这边正常

评 论