From f91218360b8bce56dd96fac888c83a6a1c6bdc32 Mon Sep 17 00:00:00 2001 From: sharonenoch <52180175+sharonenoch@users.noreply.github.com> Date: Mon, 7 Mar 2022 18:21:32 -0500 Subject: Extracting the Azure Origin url from the download link (#1480) * Extracting the Azure Origin url from the download link * Response code check to address double quotes Co-authored-by: Sharon Enoch --- utils/azure_ip_addresses_download.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'utils/azure_ip_addresses_download.sh') diff --git a/utils/azure_ip_addresses_download.sh b/utils/azure_ip_addresses_download.sh index 7f0bd81dd..8105fb87f 100755 --- a/utils/azure_ip_addresses_download.sh +++ b/utils/azure_ip_addresses_download.sh @@ -3,26 +3,41 @@ cd "$(dirname "${0}")" DEST=../src/lib/ndpi_azure_match.c.inc +LINK_TMP=/tmp/azure_link.txt TMP=/tmp/azure.json LIST=/tmp/azure.list # https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519 -ORIGIN="https://download.microsoft.com/download/7/1/D/71D86715-5596-4529-9B13-DA13A5DE5B63/ServiceTags_Public_20220124.json" +# Azure links have the format https://download.microsoft.com/download/7/1/D/71D86715-5596-4529-9B13-DA13A5DE5B63/ServiceTags_Public_.json +LINK_ORIGIN="https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519" +echo "(1) Downloading file... ${LINK_ORIGIN}" +http_response=$(curl -s -o ${LINK_TMP} -w "%{http_code}" ${LINK_ORIGIN}) +if [ "${http_response}" != "200" ]; then + echo "Error $http_response: you probably need to update the link origin url!" + return +fi + +ORIGIN="$(grep -E 'ServiceTags_Public_[[:digit:]]+.json' ${LINK_TMP} | grep -o -E 'href=\"[^"]+' | sed 's/href="//' | uniq)" +rm -f ${LINK_TMP} +if [ -z "${ORIGIN}" ]; then + echo "Error ${LINK_ORIGIN} does not contain the url format!" + return +fi -echo "(1) Downloading file..." +echo "(2) Downloading file... ${ORIGIN}" http_response=$(curl -s -o $TMP -w "%{http_code}" ${ORIGIN}) -if [ $http_response != "200" ]; then +if [ "${http_response}" != "200" ]; then echo "Error $http_response: you probably need to update the list url!" return fi -echo "(2) Processing IP addresses..." +echo "(3) Processing IP addresses..." # Note: the last "grep -v :" is used to skip IPv6 addresses tr -d '\r' < $TMP | grep / | tr -d '"' | tr -d " " | tr -d "," | grep -v : > $LIST ./ipaddr2list.py $LIST NDPI_PROTOCOL_MICROSOFT_AZURE > $DEST rm -f $TMP $LIST -echo "(3) Microsoft Azure IPs are available in $DEST" +echo "(4) Microsoft Azure IPs are available in $DEST" -- cgit v1.2.3