Get IP List from Pingdom using Powershell

Posted on

I write a lot of little scripts to do everyday tasks while I work, and I think I should share some of them.
Last week I was aggregating IP lists to allow monitoring through to a highly secured area, and I had to allow the IPs of the assigned monitoring solution, Pingdom, through to the system. Pingdom provide this information freely, thankfully. Unfortunately, they only provide it via a RSS-formatted web page.

I searched online and found that others had made scripts using Bash, but none using Powershell.

So, I wrote a neat little script to get IP lists in a PS script:

#Set Variables
$inputPage = ""
$pageOutputFile = "C:PingdomIPs1.txt"
$ipListFile = "C:PingdomIPs2.txt"
$ipListFile2 = "C:PingdomIPs3.txt"

#Variable for Loading Web Client
$web = New-Object System.Net.WebClient

#Download page to file

#Read file and Loop through each line, match line and output line to new file
foreach ($line in (Get-Content $pageOutputFile)) {
    if($line -match "<pingdom:ip>"){
        "$line" >> $ipListFile

#Remove annoying formatting
(Get-Content $ipListFile) |
Foreach-Object {$_ `
-replace "<pingdom:ip>", "" `
-replace "</pingdom:ip>", "" `
-replace " ", "" `
Set-Content $ipListFile2

At the end I get a nicely line separated list of IPs. 🙂

Leave a Reply if you find this useful

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s