提取 IP、解析域名和验证域名可用性 #78
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 提取 IP、解析域名和验证域名可用性 | |
on: | |
schedule: | |
- cron: '0 */4 * * *' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
actions: write | |
jobs: | |
Domain-Lookup: | |
runs-on: ubuntu-latest | |
steps: | |
# 检出代码库 | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
# 设置环境 | |
- name: Setup Environment | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y curl libxml2-utils jq | |
sudo apt-get clean | |
echo "$HOME/go/bin" >> $GITHUB_PATH # 将 Go 的 bin 目录添加到 PATH | |
# 提取 IP 并更新文件 | |
- name: Fetch IP and Update File | |
id: fetch_ip | |
run: | | |
URL="https://www.wetest.vip/page/cloudflare/address_v4.html" | |
OUTPUT_FILE="Fission_ip.txt" | |
echo -n > "$OUTPUT_FILE" | |
for i in $(seq 6 8); do | |
IP=$(curl -s "$URL" | xmllint --html --xpath "string(/html/body/div[2]/div[2]/div/div[2]/div[2]/table/tbody/tr[$i]/td[2])" - 2>/dev/null) | |
if echo "$IP" | grep -Pq '^(\d{1,3}\.){3}\d{1,3}$'; then | |
echo "$IP" >> "$OUTPUT_FILE" | |
echo "Valid IP found: $IP" | |
else | |
echo "Invalid IP found: $IP, skipping..." | |
fi | |
done | |
if [ -s "$OUTPUT_FILE" ]; then | |
echo "ip_file_updated=true" >> $GITHUB_OUTPUT | |
else | |
echo "No valid IPs were found. Skipping commit." | |
echo "ip_file_updated=false" >> $GITHUB_OUTPUT | |
fi | |
# 提交并推送 IP 文件更改 | |
- name: Commit and Push IP Changes | |
if: steps.fetch_ip.outputs.ip_file_updated == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add Fission_ip.txt | |
if ! git diff --quiet; then | |
git commit -m "Update Fission_ip.txt with latest IPs" | |
git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" HEAD:main | |
else | |
echo "No changes detected for Fission_ip.txt, skipping commit." | |
fi | |
# 设置 Python 环境 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
# 安装 Python 依赖 | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
# 验证并准备输入文件 | |
- name: Verify and Prepare Input Files | |
id: prepare_files | |
run: | | |
if [ ! -f "Fission_ip.txt" ]; then | |
echo "Error: Fission_ip.txt not found. Please include this file in the repository." >&2 | |
echo "file_ready=false" >> $GITHUB_OUTPUT | |
exit 1 | |
fi | |
touch Fission_domain.txt | |
echo "file_ready=true" >> $GITHUB_OUTPUT | |
# 运行 Fission 脚本 | |
- name: Run Fission script | |
if: steps.prepare_files.outputs.file_ready == 'true' | |
id: run_fission | |
run: | | |
python Fission.py | |
if [ -s "Fission_domain.txt" ]; then | |
echo "domain_file_updated=true" >> $GITHUB_OUTPUT | |
else | |
echo "Fission.py did not create domain file, skipping commit." | |
echo "domain_file_updated=false" >> $GITHUB_OUTPUT | |
fi | |
# 提交并推送域名输出文件 | |
- name: Commit and push domain output files | |
if: steps.run_fission.outputs.domain_file_updated == 'true' | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add Fission_domain.txt | |
git commit -m "Update output files from Fission.py execution" | |
git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" HEAD:main | |
# 设置 Go 环境 | |
- name: Install Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21' | |
# 安装 httpx | |
- name: Install httpx | |
run: | | |
go install github.com/projectdiscovery/httpx/cmd/httpx@latest | |
# 检查域名并更新文件 | |
- name: Check Domains and Update File | |
id: check_domains | |
run: | | |
if [ ! -f "Last-domain.txt" ]; then | |
touch Last-domain.txt | |
fi | |
# 使用 httpx 检查域名并输出状态码为 200 的域名 | |
cat Fission_domain.txt | httpx -silent -mc 200 -json > output.json | |
# 使用 jq 提取域名并保存到 Last-domain.txt | |
jq -r '.url' output.json | sed 's|^https://||g; s|^http://||g' > Last-domain.txt | |
if [ -s "Last-domain.txt" ]; then | |
echo "domain_check_updated=true" >> $GITHUB_OUTPUT | |
else | |
echo "No valid domain name was detected, skipping commit." | |
echo "domain_check_updated=false" >> $GITHUB_OUTPUT | |
fi | |
# 提交并推送域名检查输出文件 | |
- name: Commit and push domain check output files | |
if: steps.check_domains.outputs.domain_check_updated == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add Last-domain.txt | |
if ! git diff --quiet; then | |
git commit -m "Update Last-domain.txt with domains without protocol" | |
git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git" HEAD:main | |
else | |
echo "No changes detected for Last-domain.txt, skipping commit." | |
fi | |
# 删除旧的工作流运行记录 | |
- name: Delete Old Workflows | |
uses: Mattraks/delete-workflow-runs@v2 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
retain_days: 2 | |
keep_minimum_runs: 0 |