I wrote a small function in powershell that works fine, however I feel its extremely hacky and I'm sure there must be a smarter way to do this. In the interests of learning, what can I do to improve on this?
function WhatsMyIP
{
return ((Invoke-RestMethod -Uri http://ifconfig.co).split("`n") | where {$_ -match "`"ip`""}).split("<").split(">")[4]
}
I tried this with Invoke-WebRequest
but the returned data is the same, except you need to expand the .content
property to get at it, making this slightly more clunky than before.
I'd like to do this natively, I realise I can just invoke CURL or what ever but the point is that I am very likely to be on systems where CURL isn't available when I need this.