1 - 1Share
Here’s a quick one for today–I wanted to upgrade the Check External IP function that I have in my PS Profile and expand it to be able to use more than one provider. It uses dyndns.com by default. There are a handful of other reliable external IP validators, so I wanted to give myself the option of using one of them as well.
Here’s the updated version that I have in my PowerShell Profile:
Function Check-ExternalIP { [cmdletbinding()] param ( [Parameter()][ValidateSet('dyndns', 'ipchicken', 'myipaddress')] [string]$Provider) switch ($Provider) { dyndns { $source = "DynDns.com" $ip = (Invoke-WebRequest -Uri http://checkip.dyndns.com).content -replace '[^\d\.]' } ipchicken { $source = "IPChicken.com" $data = (Invoke-WebRequest -Uri https://www.ipchicken.com).ParsedHtml.body.outerText.Split("`n") $ip = $data | ? { $_ -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" } } myipaddress { $source = "MyIPAddress.com" $data = (Invoke-WebRequest -Uri http://myipaddress.com).ParsedHtml.body.outerText.split("`n") $ip = $data | ? { $_ -match "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" } } default { $source = "DynDns.com" $ip = (Invoke-WebRequest -Uri http://checkip.dyndns.com).content -replace '[^\d\.]' } } Return $ip }
Go interrogate your IP!