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
2
  • Can you clarify "not worked" ? It returns the IP Commented Aug 30, 2020 at 8:48
  • @dash-o return and show my local Ip Commented Aug 30, 2020 at 8:54

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.