It appears that ifconfig.me is sensitive to the User-Agent
string in a request.
By default, per Microsoft Learn on Invoke-WebRequest
, the User-Agent
string sent is “similar to Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.15063; en-US) PowerShell/6.0.0
with slight variations for each operating system and platform”.
I tried this using Chrome on Windows, and copied the User-Agent
string from the result (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
).
I then did Invoke-WebRequest -URI https://ifconfig.me -UserAgent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36"
, and I got a full webpage, not just the IP address.