Recently i had a scenario which i needed to look for IP’s on IIS Logs,.. so i used the solution from Post FIND ALL IPS ON LOG
but then i realized its not good enough cause i wanted to check the Hostname for each IP i’ve found so i used the solution from the Post Resolve Ip to Name
eventually I’ve decided to combined it together and make benefit of using all in one script which will find any ip address from any file then it will
try to resolve each IP Address from the file to Hostname, here you go –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#This script is scanning any file name for IP Addresses and try to Resolve its HostName function ScanIP2Name { <# .Synopsys Scan any file for IP Addresses ,then try to resolve name. .Description if you having a large txt/xml/config file and you would like to know which IP Addresses exist on this file, just ran this script and it'll show you the IP Addresses was found on chosen file. .Example C:\ScanIP2Name d:\Internet\FolderName\FileName.txt-xml-config-html #> param($path) $IPRegex = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" $ipadds = @() $ipadd = Get-Content $path | Select-String -Pattern $IPRegex -AllMatches | % { $_.Matches } | % {$_.value} foreach ($ip in $ipadd) { try {$ipadds += [System.Net.Dns]::GetHostEntry($IP)} catch{Write-Host $IP could not be Resolved -BackgroundColor Black -ForegroundColor Red} } return $ipadds } |
(Visited 177 times, 1 visits today)