0

I need to get this to display correctly like this:

Public IP Address . . . . . . . . : (my ip address)

here's what I have for now:

set c=curl "http://icanhazip.com/"

set /p t="   Public IP Address . . . . . . . . : %c%

trying to display curl alone as %c% works as it should but when adding it to string or echo it doesn't, any idea?

Nico Nekoru
  • 2,840
  • 2
  • 17
  • 38
Xetap
  • 25
  • 5
  • So you are taking input where it will prompt `Public IP Address . . . . . . . : `? – Nico Nekoru Jun 04 '20 at 23:24
  • that's what I'm currently getting but I need to get it to show like this "Public IP Address . . . . . . . . : 142.94.37.204" – Xetap Jun 04 '20 at 23:27
  • Setting a variable to `curl "http://icanhazip.com/"` the variable will become equal to the string `curl "http://icanhazip.com/"`. To set a variable as a command output, use a `for` loop. – Nico Nekoru Jun 04 '20 at 23:27
  • Use `for /f %%a in ('curl "http://icanhazip.com/"') do (set c=%%~a)` – Nico Nekoru Jun 04 '20 at 23:30
  • It's working :D however I'm getting some random text "% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 16 100 16 0 0 16 0 0:00:01 --:--:-- 0:00:01 85" it displays right before "Public IP Address . . . . . . . . : (my ip)" – Xetap Jun 04 '20 at 23:36
  • 1
    pipe the result of your `curl.exe` command through `find.exe`, e.g. `('curl "http://icanhazip.com/" ^| find "Public IP Address"')` – Compo Jun 04 '20 at 23:47
  • Or change your options. Depending upon your specific task, one or a combination of `[-f|--fail] [-S|--show-error] [-s|--silent]`. – Compo Jun 05 '20 at 12:25

1 Answers1

0

Thanks to Neko Musume, for /f %%a in ('curl -s "http://icanhazip.com/"') do (set c=%%~a) this solved it.

Xetap
  • 25
  • 5