0

How to use random ip address in Curl request,I'm using this code and worked

printf "%d.%d.%d.%d\n" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))"

but when use this code in Curl request and test on http://ifconfig.me not worked

curl --header 'X-Forwarded-For: printf "%d.%d.%d.%d\n" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))"' http://ifconfig.me
Cyrus
  • 84,225
  • 14
  • 89
  • 153

1 Answers1

1

Is suggest to use command substitution. Replace

curl --header 'X-Forwarded-For: printf "%d.%d.%d.%d\n" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))"' http://ifconfig.me

with

curl --header "X-Forwarded-For: $(printf "%d.%d.%d.%d\n" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))" "$((RANDOM % 256))")" http://ifconfig.me
              ^                 ^^                                                                                                      ^^

I switched from '...' to "..." and from printf "..." to $(printf "...").


See: Difference between single and double quotes in bash

Cyrus
  • 84,225
  • 14
  • 89
  • 153