Check External IP Function

Check External IP Function

  •  
  •  
  • 1
  •  
  •  
  •  
    1
    Share

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!

Published by Aaron Guilmette

Helping companies conquer inferior technology since 1997. I spend my time developing and implementing technology solutions so people can spend less time with technology. Specialties: Active Directory and Exchange consulting and deployment, Virtualization, Disaster Recovery, Office 365, datacenter migration/consolidation, cheese.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.