I have a function to get my external IP from ifconfig.me. It returns what looks like a plain string from "http://ifconfig.me/ip"
function Get-ExternalIP
{
$url = "http://ifconfig.me/ip"
$webClient = new-object System.Net.WebClient
$ip = $webClient.downloadstring($url)
return $ip
}
This successfully returns what looks like an IP Address, however its not encoded in a way that it is properly handled by powershell.
$ip = Get-ExternalIP
$ip -as [ipaddress]
Fails.
All the functions I'm attempting to do with this string are failing. I'm importing a different IP as a string from a text file and comparing the two is failing even if they are 'identical'.
It gets worse, when I attempt to write it out to a text file I'm getting extra line breaks and a hex heditor shows loads of extra data thats not getting shown.
Top is the 'bad data', bottom is an example of how I would expect it to look.
I'm assuming that this is due to the encoding of the text object I'm extracting, but I'd like to understand how i can find out what the encoding is and re-encode it in a way that I can work with. I'm sure there is a simple cast(?) I can do? But I don't know how I would go about finding that out.
$ip.trim() -as [ipaddress]returnsTRUE! The value has an extra 'empty' cahr at the end.