Posted On May 21, 2020

PowerShell: Resolving URL to Public IP

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Resolving URL to Public IP
# URL can be with http, https, full paths, or just domain
$url='https://google.com/domains'

# This will return the position 0 public IP of the provided URL's domain
$regexDomain='(http[s]:\/{2}){0,1}([\d\w\.-]+)\/{0,1}'
$domain=.{[void]($url -match $regexDomain);$matches[2]}
$publicIP=[System.Net.Dns]::GetHostAddresses($domain)[0].IPAddressToString
write-host $publicIP

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Alternative to Test-NetConnection for Legacy Windows

This little snippet is useful as a helper function to quickly determine port connectivity between…

PowerShell: Get Connected Port by Process Name

# getProcessConnectionPort.ps1 $computerlist=@' SQL1 SQL2 '@ $computernames=@($computerList -split "`n")|%{$_.Trim()} $processname='sqlservr' $state='Established' $results=@() foreach ($computername in…

PowerShell: Performing System Disk Cleanup

Version 2: # cleanupWindows.ps1 # Version 0.0.2 ################################## Excuting Program as an Administrator #################################### #…