为方便学术资源查阅,借助其EarthVPN免费VPN节点进行科学上网。结合所学技术,抓取接口信息,编写Shell脚本。

Shell脚本

执行效果

脚本内容
#!/bin/bash
# EarthVPN免费节点链接列表获取
# Author: [email protected]
# Date: 2023-03-25
# Version: 0.0.2

# 随机Md5值
Time_Stmp=`date +%s |md5sum|head -c 32`
# 获取节点列表
Earth_VPN_List=`curl -s -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36' "https://earth-vpn.net/servers/?id=nabbmpekekjknlbkgpodfndbodhijjem&t=1612946444175&mt=1612946444172&lt=46817&uid=a1164cd1-b429-4b27-b327-125c31ce8bc1&hash=${Time_Stmp}" |jq -r '.locations[]'`
# 获取节点区域
Earth_VPN_Country_Name_List=`echo "${Earth_VPN_List}"|jq -r '.country_name'`
# 以换行符为分隔符
IFS=$'\n'
# 循环输出节点区域代理
for Earth_VPN_Country_Name in ${Earth_VPN_Country_Name_List};do
       # 格式化节点信息
       Earth_VPN_Country_Node_List=`echo "${Earth_VPN_List}" |jq -r "select(.country_name==\"${Earth_VPN_Country_Name}\")"|jq -r ".nodes[]"|awk '{if(NR%5==0){printf $0 "\n"}else{printf "%s",$0}}'|sed 's/ //g'`
       for Earth_VPN_Country_Node in ${Earth_VPN_Country_Node_List};do
              # 链接方式
              Earth_VPN_Country_Node_Schema=`echo "${Earth_VPN_Country_Node}"|jq -r .schema`
              # IP地址
              Earth_VPN_Country_Node_Address=`echo "${Earth_VPN_Country_Node}"|jq -r .ip`
              # IP端口
              Earth_VPN_Country_Node_Port=`echo "${Earth_VPN_Country_Node}"|jq -r .port`
              VPN_Connected_Info=`nc -zv -w 0.5  "${Earth_VPN_Country_Node_Address}" "${Earth_VPN_Country_Node_Port}" 2>&1`
              if [[ "${VPN_Connected_Info}" =~ "Connected to ${Earth_VPN_Country_Node_Address}:${Earth_VPN_Country_Node_Port}" ]];then
                     # 链接时间
                     VPN_Connected_Time=`echo "${VPN_Connected_Info}"|awk '/0 bytes sent,/ {print $9}'`
                     echo "${VPN_Connected_Time}s,Zone: ${Earth_VPN_Country_Name} ,Type:${Earth_VPN_Country_Node_Schema} ,Address: ${Earth_VPN_Country_Node_Address}:${Earth_VPN_Country_Node_Port}"
              fi
       done
done
END

本文标题:通过Shell脚本获取EarthVPN免费节点链接列表

本文作者:宇宙最帅的男人

本文链接:https://lolicp.com/others/202115105.html

版权声明:转载或者引用本文内容请注明来源及原作者,本文著作权归作者 (宇宙最帅的男人) 所有。

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

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