Tech Tip: TCP/IP Access Using bash
Most of us default to wget, curl, netcat and others when in need of network data from the commandline, not knowing, or perhaps forgetting, that bash often provides the support that we need using redirection from /dev/proto/host/port.
$ cat </dev/tcp/time.nist.gov/13 55103 09-09-29 17:58:55 50 0 0 0.0 UTC(NIST) *
Reads the time in Daytime Protocol (RFC-867) from the NIST Internet Time Service server (documented at tf.nist.gov/service/its.htm).
The Advanced Bash-Scripting Guide includes some more involved examples in chapter 27, covering sending a protocol request, getting web pages, and even UDP use.
Editor's Note: If this does not work for you, make sure to read the comments below, this option is not enabled on all distros (among them, some versions of Ubuntu).
Free DevOps eBooks, Videos, and more!
Regardless of where you are in your DevOps process, Linux Journal can help!
- Linux Journal
- Be a Mechanic...with Android and Linux!
- New Products
- Users, Permissions and Multitenant Sites
- Flexible Access Control with Squid Proxy
- Security in Three Ds: Detect, Decide and Deny
- High-Availability Storage with HA-LVM
- Tighten Up SSH
- DevOps: Everything You Need to Know
- Solving ODEs on Linux
- Non-Linux FOSS: MenuMeters