Friday, July 6, 2018

Powershell to lookup abuse emails for an IP address

#$ErrorActionPreference= 'silentlycontinue'
$k = Get-Content "H:\PowershellPlayground\IPAbuseLookup\IPs.txt"
foreach($i in $k)
{
    $original = $i
    $reversed = $i -replace '^(\d+)\.(\d+)\.(\d+)\.(\d+)$','$4.$3.$2.$1.abuse-contacts.abusix.org'
    try
    {
        Resolve-DnsName -Type TXT $reversed -DnsOnly -ErrorAction Stop | select @{l='IP';e={$original}}, @{l='AbuseEmail';e={$_.Strings}}, @{l='Status';e={"SUCCESS"}}
    } Catch{
        [pscustomobject]@{
            IP = $original
            AbuseEmail = ''
            Status = "ERROR"
        }
    }
}

No comments:

Post a Comment