Last active
September 14, 2022 22:05
-
-
Save Rugby-Ball/99c6e5ec86e5bb319eb3dec3edf6a02b to your computer and use it in GitHub Desktop.
Enter in the IP, CNAME, or a wildcard search string in $iplist to look in ALL Route 53 Hosted Zones. #Utility #Inventory #Route_53 #AWS #Public
This file contains hidden or 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
| #search_rt53_entries_for_IP.ps1 | |
| #Enter in the IP, CNAME, or a wildcard search string in $iplist to look in ALL Route 53 Hosted Zones. | |
| #Version: 1.5 | |
| #Date Created: 10/19/2020 | |
| #Date Updated: 9/14/2022 | |
| #Created: Ed Walsh | |
| # | |
| # | |
| #Use this to check PoSh version and save to correct location for cvs outputs. | |
| $timestamp = get-date -format yyyyMMddHHmmss | |
| $subfolder = if (($PSVersionTable.PSEdition) -eq "Core") { if ( $True -eq $iswindows ) { "\Documents\" } Else { "" } } Else {"\Documents\"} | |
| $mydocuments = $home + $subfolder #Old Way of doing it# [environment]::getfolderpath("mydocuments") | |
| $fileName = "RT53-Zones-Entries-Search-Inventory-"+ [string]$timestamp + ".csv" | |
| $filePath = Join-Path $mydocuments $fileName | |
| #To only search in one HostedZone and not all, enter in the Domain. To check all HostedZones enter in "" | |
| $Domain = "" | |
| # List out the RT53 Target IP's or urls to search for, Can be a comma seperated list. NOTE, if you search for an IP make sure you also include the AWS internal IP URL, example: "192.165.21.75","ip-192-165-21-75.ec2.internal" | |
| $iplist = "dualstack.ext-prod-1216304511.us-west-1.elb.amazonaws.com", "grand.website.com.edgesuite.net","smart.website.com.edgesuite.net","192.165.21.75","ip-192-165-21-75.ec2.internal" | |
| $a = @() | |
| $B = @() | |
| $rt53out = @() | |
| Import-Module AWSPowerShell | |
| $zones = Get-R53HostedZones | |
| foreach ($zone in $zones) { | |
| $rt53out += if ($Domain -eq "" -or $zone.Name -eq "$Domain.") { | |
| $zname = $zone.Name | |
| $(Get-R53ResourceRecordSet -HostedZoneId $($zone.Id)).ResourceRecordSets | Where-object { ($_.Type -eq "A" -or $_.Type -eq "CNAME") -and $_.Name -notlike "*_domainkey*" } | Select-Object @{Name = 'RT53_Zone'; Expression = { $zname.Substring(0, $zname.Length - 1) } }, @{Name = 'URL'; Expression = { $_.Name.Substring(0, $_.Name.Length - 1) } }, Type, @{Name = 'Value'; Expression = { if ($_.AliasTarget -ne $null) { (($_.AliasTarget).DNSName).TrimEnd(".") } Else { ($_.ResourceRecords | Select-Object -ExpandProperty Value).TrimEnd(".") } } } | |
| } | |
| } | |
| foreach ($ipsearch in $iplist){ | |
| foreach ($zvalue in $rt53out) { | |
| $a += if (($zvalue).Value -like $ipsearch ) { | |
| [PsCustomObject][ordered]@{ | |
| 'Domains_Searched' = if($domain -eq ""){'All Domains'} Else {$domain} | |
| 'Has_Entry' = 'Yes' | |
| 'Rt53_Zone' = ($zvalue.RT53_zone) | |
| 'Type' = ($zvalue.Type) | |
| 'URL' = ($zvalue.url) | |
| 'Value' = ($zvalue.value) | |
| } | |
| } | |
| } | |
| $B += if(-not( $a )) { | |
| [PsCustomObject][ordered]@{ | |
| 'Domains_Searched' = if($domain -eq ""){'All Domains'} Else {$domain} | |
| 'Has_Entry' = 'No' | |
| 'Rt53_Zone' = "" | |
| 'Type' = "" | |
| 'URL' = "" | |
| 'Value' = $ipsearch | |
| } | |
| } | |
| Else { | |
| $A | |
| } | |
| $A = @() | |
| } | |
| $B | Out-GridView | |
| $b | Export-Csv -NoTypeInformation -Append -Path $filepath | |
| Write-Output "Exported to: $filePath" | |
| Write-Output "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|||||||////////////////////////////////////" |
Author
Author
8/9/2021: Version 1.4
Fixed the issue where if it was an Alias record the value returned nothing. You need to check for Alias and then return specific records for Value.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Handy script if you have a lot of RT53 HostedZones in AWS and need to look in each for the Target of the entries.
When the Akamai DNS outage hit on 7/22/2021, was able to scan for edgesuite entries and find all of my entries across all my HostedZones.