aboutsummaryrefslogtreecommitdiff
path: root/utils/whatsapp_ip_addresses_download.sh
blob: 72284101559dbe497fafb589546a223d12f1e6ec (plain)
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
#!/bin/sh

set -e

cd "$(dirname "${0}")" || exit 1

DEST=../src/lib/inc_generated/ndpi_whatsapp_match.c.inc
TMP=/tmp/wa.zip
LIST=/tmp/wa.list
USER_AGENT='Mozilla/5.0 (X11; Linux x86_64) Gecko/20100101 Firefox'
IP_LINK_URL='https://developers.facebook.com/docs/whatsapp/guides/network-requirements/'


echo "(1) Scraping Facebook WhatsApp IP Adresses and Ranges..."
ORIGIN="$(curl -H "User-Agent: ${USER_AGENT}" -s "${IP_LINK_URL}" | sed -n 's/.*<a href="\(https:\/\/scontent.*\.zip?.*\)" target="_blank">.*/\1/gp')"

if [ -z "${ORIGIN}" ]; then
    echo "Error: IP webpage list does not contain any addresses. A REGEX update may be required."
    exit 1
fi

echo "(2) Downloading file... ${ORIGIN}"
http_response=$(curl -H "User-Agent: ${USER_AGENT}" -H "Referer: https://developers.facebook.com/" -s -o $TMP -w "%{http_code}" ${ORIGIN})
if [ "$http_response" != "200" ]; then
    echo "Error $http_response: you probably need to update the list url!"
    echo "Response: $(cat ${TMP})"
    exit 1
fi

echo "(3) Processing IP addresses..."
unzip -p /tmp/wa.zip "WhatsApp IPs (IPv4 Only) 2022-07-26 - 2022-07-30.txt" > $LIST
./ipaddr2list.py $LIST NDPI_PROTOCOL_WHATSAPP > $DEST
rm -f $TMP $LIST

echo "(4) WhatsApp IPs are available in $DEST"
exit 0