{"id":4646,"date":"2023-01-07T19:10:21","date_gmt":"2023-01-08T03:10:21","guid":{"rendered":"https:\/\/tungle.ca\/?p=4646"},"modified":"2023-03-01T18:36:31","modified_gmt":"2023-03-02T02:36:31","slug":"count-how-many-ip-addresses-in-aws-per-us-east-1-region","status":"publish","type":"post","link":"https:\/\/tungle.ca\/?p=4646","title":{"rendered":"Count how many IP addresses in AWS US-East-1 region"},"content":{"rendered":"\n<p>In this article, I will demonstrate how to count how many IP addresses in US-East-1 region.<\/p>\n\n\n\n<p>We can get a list of IP address from AWS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">https:\/\/ip-ranges.amazonaws.com\/ip-ranges.json<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-25.png\" alt=\"\" class=\"wp-image-4647\" width=\"479\" height=\"403\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-25.png 910w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-25-300x253.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-25-768x646.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-25-200x168.png 200w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Download and save the JSON file to aws-ip-ranges.json in the present working directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Invoke-WebRequest -Uri https:\/\/ip-ranges.amazonaws.com\/ip-ranges.json -OutFile aws-ip-ranges.json<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"43\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-26-1024x43.png\" alt=\"\" class=\"wp-image-4650\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-26-1024x43.png 1024w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-26-300x13.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-26-768x32.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-26-1536x64.png 1536w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-26-2048x86.png 2048w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-26-200x8.png 200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Load the JSON file and convert JSON formatted file to custom PSObject of&nbsp;PowerShell.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$data = Get-Content -Path aws-ip-ranges.json -Raw | ConvertFrom-Json<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"201\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-27-1024x201.png\" alt=\"\" class=\"wp-image-4652\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-27-1024x201.png 1024w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-27-300x59.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-27-768x151.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-27-1536x301.png 1536w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-27-2048x402.png 2048w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-27-200x39.png 200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Extract the list of IP addresses for the US-East-1 region and AMAZON service.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$ip_addresses = $data.prefixes | Where-Object { $_.region -eq 'us-east-1' -and $_.service -eq 'AMAZON' } | Select-Object -ExpandProperty ip_prefix<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"211\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-28-1024x211.png\" alt=\"\" class=\"wp-image-4653\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-28-1024x211.png 1024w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-28-300x62.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-28-768x158.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-28-1536x317.png 1536w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-28-2048x422.png 2048w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-28-200x41.png 200w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Below is a PS script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\"># This script is using to extract IP address in US-East-1 region of AWS\n# Download and save the JSON file to aws-ip-ranges.json in the present working directory\nInvoke-WebRequest -Uri https:\/\/ip-ranges.amazonaws.com\/ip-ranges.json -OutFile aws-ip-ranges.json\n\n# Load the JSON file and convert JSON formatted file to custom PSObject or Hashtable object of PowerShell\n$data = Get-Content -Path aws-ip-ranges.json -Raw | ConvertFrom-Json\n\n# Extract the list of IP addresses for the US-East-1 region1 and service is AMAZON\n$ip_addresses = $data.prefixes | Where-Object { $_.region -eq 'us-east-1' -and $_.service -eq 'AMAZON' } | Select-Object -ExpandProperty ip_prefix\n\n# Print the list of IP addresses of AWS US-East-1 Region\n$ip_addresses<\/code><\/pre>\n\n\n\n<p>Run the script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">.\/aws-ip.PS1<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-29.png\" alt=\"\" class=\"wp-image-4654\" width=\"346\" height=\"314\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-29.png 802w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-29-300x272.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-29-768x697.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-29-200x182.png 200w\" sizes=\"auto, (max-width: 346px) 100vw, 346px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Save all range IP addresses when running the script aws-ip.PS1 to aws-ip.txt<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">.\/aws-ip.PS1 &gt; aws-ip.txt<\/code><\/pre>\n\n\n\n<p>Using the following PowerShell script to extract how many IP addresses in the Amazon CIDR subnet such as 52.4.0.0\/14.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">param(\n    [string]$filename\n)\n\nfunction Count-IPs([string]$netblock) {\n    # Get CIDR value from the netblock\n    $cidr = [int]$netblock.Split('\/')[1]\n    # Return the number of IP addresses in the netblock above\n    return [math]::Pow(2, 32 - $cidr)\n}\n\nif (!$filename) {\n    # Display the error message if the filename parameter is not provided\n    Write-Output \"Usage: $($MyInvocation.MyCommand) &lt;filename with CIDR masks&gt;\"\n}\n\n$ipcount = 0\nGet-Content $filename | ForEach-Object {\n    $ipcount += Count-IPs $_\n}\nWrite-Output $ipcount<\/code><\/pre>\n\n\n\n<p>Run the script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">.\/countips.PS1 aws-ip.txt<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-30-1024x98.png\" alt=\"\" class=\"wp-image-4655\" width=\"368\" height=\"35\" srcset=\"https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-30-1024x98.png 1024w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-30-300x29.png 300w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-30-768x74.png 768w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-30-200x19.png 200w, https:\/\/tungle.ca\/wp-content\/uploads\/2023\/01\/image-30.png 1042w\" sizes=\"auto, (max-width: 368px) 100vw, 368px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>There are 17,728,227 IP addresses in AWS US-East-1 region.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, I will demonstrate how to count how many IP addresses in US-East-1 region. We can get a list of IP address from AWS. Download and save the JSON file to aws-ip-ranges.json in the present working directory. Load the JSON file and convert JSON formatted file to custom PSObject of&nbsp;PowerShell. Extract the list [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,9,7],"tags":[20,10,12],"class_list":["post-4646","post","type-post","status-publish","format-standard","hentry","category-cloud","category-microsoft","category-powershell","tag-cloud","tag-microsoft","tag-powershell"],"_links":{"self":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/4646","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4646"}],"version-history":[{"count":18,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/4646\/revisions"}],"predecessor-version":[{"id":4778,"href":"https:\/\/tungle.ca\/index.php?rest_route=\/wp\/v2\/posts\/4646\/revisions\/4778"}],"wp:attachment":[{"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4646"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4646"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tungle.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4646"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}