-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (149 loc) · 6 KB
/
Domain-Lookup.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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