Created
January 16, 2020 04:45
-
-
Save rrbutani/3678b8315e3b86aed7438713753dd39a to your computer and use it in GitHub Desktop.
π
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
#!/usr/bin/env bash | |
# $1 : battery code | |
try_battery_code() { | |
raw=$(curl -s "https://duckduckgo.com/html" \ | |
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86; rv:49.0) Gecko/20100101 Firefox/49.0' \ | |
-H 'Accept-Language: en-US,en;q=0.5' \ | |
--compressed -H 'Referer: https://duckduckgo.com/' \ | |
-H 'Content-Type: application/x-www-form-urlencoded' \ | |
-H 'Connection: keep-alive' \ | |
-H 'Upgrade-Insecure-Requests: 1' \ | |
-H 'TE: Trailers' \ | |
--data "q=${1}+battery&b=&kl=us-en" \ | |
| grep "${1}" \ | |
| grep -i "lipo\|Li-Po" \ | |
| grep "result__snippet") \ | |
&& { | |
echo "${1}:" | |
i=0 | |
readarray links <<<"$(echo "${raw}" | cut -d '=' -f3- | cut -d '>' -f1)" | |
# echo "got: ${links[0]}" | |
for l in "${links[@]}"; do | |
echo " - [$((i++))]($(tr -d $'\n' <<< "${l}"))" | |
done | |
echo "" | |
} > ${1}.part \ | |
|| { | |
return 1 | |
} | |
} | |
# Battery codes are of the form: 042535 | |
# 1,000,000 codes to try! (excluding the 7 digit ones). | |
count=0 | |
limit=$(($(nproc) * 10)) | |
for i in {0..1000000..5}; do | |
code="$(printf "%06d" ${i})" | |
try_battery_code "${code}" && ((count++)) & | |
echo -ne "On ${code}\r" | |
sleep 15 | |
# while [ $(jobs -rp | wc -l) -gt ${limit} ]; do | |
# sleep 1 | |
# done | |
done | |
cat *.part > res.md | |
echo "${count} ($(ls -l *.part | wc -l))batteries found!" >> res.md | |
rm *.part |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment