28 lines
1006 B
Bash
28 lines
1006 B
Bash
---
|
|
title: "Bash has a builtin network client"
|
|
author: "James Pace"
|
|
date: "2024/01/12"
|
|
---
|
|
|
|
I've been playing with using Rust on microcontrollers that have
|
|
ethernet support with the microcontroller using UDP to communicate
|
|
with the rest of the world.
|
|
|
|
When testing the code I wrote on the microcontroller, I searched for how to send
|
|
udp packets from the command line (expecting to find the right incantation for
|
|
netcat, which I've used in the past but don't remember the options for.)
|
|
What I actually found was more interesting.
|
|
|
|
Apparently, bash has builtin "pseudo devices" that allow you to read and write
|
|
from a TCP or UDP port like you were reading or writing from a file.
|
|
For example, to send the string "hello" to my microcontroller at 192.168.1.109 on
|
|
port 1337, I used the command
|
|
```bash
|
|
echo "hello" > /dev/udp/192.168.1.109/1337
|
|
```
|
|
|
|
Bash supports the same thing for TCP connections as well using similar syntax.
|
|
|
|
That is a lot easier to remember than netcat, and I'll definitely use
|
|
it again.
|