I want to get the Output of my Ip Address only inside the Anaconda Powershell in Windows.
curl https://ipinfo.io/ip
Gives me the following:
StatusCode : 200
StatusDescription : OK
Content : 22.031.123.456
RawContent : HTTP/...
...
...
...
...
Content-Type: text/html; charset=utf-8
Date: ...
Via:...
Forms : {}
Headers : {[..., *], [...], [...],
[..., ...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : ...
RawContentLength : ...
As you can see, "Content" shows my IP Adress. But I can't get the IP-Address without any other informations.
Note: "curl api.ipify.org" and "curl ipinfo.io/ip" and others are doing the exact same thing.
In Windows PowerShell, curl
does not refer to the external curl.exe
program; instead, it is a built-in alias for PowerShell's Invoke-WebRequest
cmdlet.
In order to invoke curl.exe
, include the filename extension, .exe
:
curl.exe ipinfo.io/ip # Note: The https:// part isn't strictly needed.
Note that this is no longer necessary in PowerShell (Core) v6+, where the curl
alias has been removed, along with others, so as not to shadow external programs that come with the operating system.
Also note that you could also have used the Invoke-RestMethod
cmdlet, which - unlike Invoke-WebRequest
, which returns a wrapper object around the actual data - returns the response data directly (and, as applicable, parses XML data into [xml]
instances and JSON data into [pscustomobject]
instances); its built-in alias is irm
:
irm ipinfo.io/ip # irm == Invoke-RestMethod
As a general tip: To determine which command (a PowerShell-native one or an external program) a given name such as curl
refers to, use the Get-Command
cmdlet.
-All
switch, you'll potentially see shadowed command forms.
On Windows, if an external program is shadowed, you can still invoke it by excluding the .exe
extension, as shown.
Generally, if a shadowed command is of a different type than the effective command, you can use the Get-Command
's -Type
parameter to target the shadowed command and invoke it via &
, the call operator; e.g., the (less desirable) alternative to appending .exe
on Windows would be:
& (Get-Command -Type Application curl) ipinfo.io/ip