Connecting to website without curl or bash
nc
opens a connection to port 80 ongoogle.com
- The
echo
statement is a valid GET request, using HTTP/1.0 protocol > /dev/null 2>&1
redirects bothstdout
andstderr
, producing no output- You can tell success by the exit code, in
$?
(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