I'm trying to connect to a website like this "examplesite.com:9000/link"
using a method like this:
echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
I've seen people ping google with the above code.
I can use curl
or wget
to go to that site but I don't wanna use those methods because I'm using a microcontroller that doesn't support curl
or wget
.
Could someone explain how the above code is working?
nc
opens a connection to port 80 on google.com
echo
statement is a valid GET request, using HTTP/1.0 protocol> /dev/null 2>&1
redirects both stdout
and stderr
, producing no output$?
(value of 0 means success)You could write this shorter:
echo -e "GET /\n\n" | nc google.com 80
And more portable (without echo -e
):
printf "GET /\n\n" | nc google.com 80
Or more portable but still with echo
:
{ echo GET /; echo; } | nc google.com 80
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With