forked from jhassine/server-ip-addresses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-csv.sh
executable file
·46 lines (35 loc) · 1.69 KB
/
generate-csv.sh
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
#!/usr/bin/env bash
set -euo pipefail
CIDR_REGEX='[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9]\{1,\}'
IP_ADDRESS_REGEX='([0-9]{1,3}[\.]){3}[0-9]{1,3}'
cd /data
cidrs_aws=$(wget -qO- https://ip-ranges.amazonaws.com/ip-ranges.json | grep -o "$CIDR_REGEX" | sort -V)
echo -n "AWS CIDRs: "
echo "$cidrs_aws" | wc -l
cidrs_cloudflare=$(wget -qO- https://www.cloudflare.com/ips-v4 | sort -V)
echo -n "CloudFlare CIDRs: "
echo "$cidrs_cloudflare" | wc -l
cidrs_gcp=$(wget -qO- https://www.gstatic.com/ipranges/cloud.json | grep -o "$CIDR_REGEX" | sort -V)
echo -n "GCP CIDRs: "
echo "$cidrs_gcp" | wc -l
cidrs_azure=$(wget -qO- $(wget -qO- -U Mozilla https://www.microsoft.com/en-us/download/confirmation.aspx?id=56519 | grep -Eo 'https://download.microsoft.com/download/\S+?\.json' | head -n 1) | grep -o "$CIDR_REGEX" | sort -V )
echo -n "Azure CIDRs: "
echo "$cidrs_azure" | wc -l
echo -e "$cidrs_aws\n$cidrs_cloudflare\n$cidrs_gcp\n$cidrs_azure\n" | uniq > datacenters.txt
get_csv_of_low_and_high_ip_from_cidr_list()
{
cidrs=$1
vendor=$2
echo "$cidrs" | while read cidr;
do
hostmin=$(ipcalc -n $cidr |cut -f2 -d=)
hostmax=$(ipcalc -b $cidr |cut -f2 -d=)
echo "\"$cidr\",\"$hostmin\",\"$hostmax\",\"$vendor\""
done
}
echo '"cidr","hostmin","hostmax","vendor"' > datacenters.csv
get_csv_of_low_and_high_ip_from_cidr_list "$cidrs_aws" "AWS" | uniq >> datacenters.csv
get_csv_of_low_and_high_ip_from_cidr_list "$cidrs_cloudflare" "CloudFlare" | uniq >> datacenters.csv
get_csv_of_low_and_high_ip_from_cidr_list "$cidrs_gcp" "GCP" | uniq >> datacenters.csv
get_csv_of_low_and_high_ip_from_cidr_list "$cidrs_azure" "Azure" | uniq >> datacenters.csv
echo "Success!"