Skip to content

Instantly share code, notes, and snippets.

@LozanoMatheus
Last active August 24, 2023 13:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LozanoMatheus/a3eb5a1fcc10661ff1e25ff1fe7c9e1e to your computer and use it in GitHub Desktop.
Save LozanoMatheus/a3eb5a1fcc10661ff1e25ff1fe7c9e1e to your computer and use it in GitHub Desktop.
A simple request - HTTP request with native Bash and without curl/wget/*
#!/usr/bin/env bash +x
## Do you need to test your exposed app but you don't have curl/wget/* installed?
## The ":" is a built-in command and it works similar to true. Let's say, ":" is more portable than "true"
## Simple and easy
:> /dev/tcp/localhost/22
## Why using timeout? If any side has a firewall and it's dropping the packages, the request will take ~80 seconds to get the timeout.
## Let's try first with Google :D
## In this case, we don't have output, but the return code will be 0
timeout 10s bash -c ':> /dev/tcp/google.com/443'
## Return code
0
## Now let's try locally. With return code 1
timeout 10s bash -c ':> /dev/tcp/localhost/443'
## Output
bash: connect: Cannot assign requested address
bash: /dev/tcp/localhost/443: Cannot assign requested address
## Return code
1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment