Extract IPs from URL #10
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: Extract IPs from URL | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '*/30 * * * *' # Runs daily at midnight (adjust as needed) | |
jobs: | |
extract-ips: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Download the source file | |
- name: Download source file | |
run: curl -s -o trackers_all_ip.txt https://raw.githubusercontent.com/ngosang/trackerslist/refs/heads/master/trackers_all_ip.txt | |
# Download the source file with trackers | |
- name: Download source file with trackers | |
run: curl -s -o trackers_all_from_src1.txt https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt | |
- name: Concatenate custom hosts | |
run: | | |
# Concatenate custom_hosts.txt to trackers_all.txt | |
cat custom_hosts.txt trackers_all_from_src1.txt > trackers_all.txt | |
echo "Combined trackers_all.txt with custom_hosts.txt" | |
cat trackers_all.txt | |
# Extract only the IPs from trackers_all_ip.txt | |
- name: Extract IP addresses from the file | |
run: | | |
grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' trackers_all_ip.txt > extracted_ips.txt | |
echo "Extracted IPs from file:" | |
cat extracted_ips.txt | |
# Extract hostnames from the URLs and resolve to IP addresses | |
- name: Extract IP addresses from hosts in trackers_all.txt | |
run: | | |
echo "Extracting IPs from the host list..." | |
# Extract hostnames from both http:// and udp:// URLs | |
grep -oP '(?<=://)[^:/]+' trackers_all.txt > hostnames.txt | |
# Resolve each hostname to IP addresses and save it | |
while IFS= read -r host; do | |
ips=$(dig +short $host) | |
if [ -n "$ips" ]; then | |
echo "Resolved $host to the following IPs:" | |
for ip in $ips; do | |
# Check if the resolved IP is a valid IPv4 address | |
if [[ "$ip" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then | |
echo "$ip" | |
echo "$ip" >> new_extracted_ips.txt | |
else | |
echo "Skipping non-IP value: $ip" | |
fi | |
done | |
else | |
echo "Failed to resolve $host" | |
fi | |
done < hostnames.txt | |
# Combine new IPs with previous ones, ensuring uniqueness | |
- name: Combine and ensure uniqueness of IPs | |
run: | | |
# Combine new extracted IPs with the previous list and ensure uniqueness | |
cat extracted_ips.txt new_extracted_ips.txt | sort | uniq > extracted_ips.txt | |
echo "Combined unique IPs:" | |
cat extracted_ips.txt | |
# Commit and push the combined extracted IPs file | |
- name: Commit and push changes | |
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 extracted_ips.txt | |
git commit -m "Update extracted IPs" | |
git push |