# Sending binary data to a TCP or UDP connection in bash

**URL:** <https://linux-tips.com/t/sending-binary-data-to-a-tcp-or-udp-connection-in-bash/250>\
**Category:** Network\
**Created:** [March 9, 2015, 3:35pm UTC](https://linux-tips.com/t/sending-binary-data-to-a-tcp-or-udp-connection-in-bash/250 "2015-03-09T15:35:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![demirten](https://linux-tips.com/user_avatar/linux-tips.com/demirten/32/64_2.png) [@demirten](https://linux-tips.com/u/demirten)\
**Post date:** [March 9, 2015, 3:35pm UTC](https://linux-tips.com/t/sending-binary-data-to-a-tcp-or-udp-connection-in-bash/250/1 "2015-03-09T15:35:01Z")

</div>

Sometimes you may want to send binary data to a TCP or UDP connection. You can send text data to a TCP port with **telnet** command but it doesn’t work for binary streams. There are some other alternatives which you can use like **netcat** or **socat** but it is also possible to send any data from TCP or UDP with just using bash shell’s internal functionality. For example to send text data to 192.168.2.5’s port 80 you can use:

```
$ echo "GET / HTTP/1.0" > /dev/tcp/192.168.2.5/80

```

or to send 160 bytes of a binary data to port 9000:

```
$ dd if=binary.dat bs=160 count=1 > /dev/tcp/192.168.2.5/9000

```

it is also possible to use udp too:

```
$ dd if=binary.dat bs=160 count=1 > /dev/udp/192.168.2.5/9000

```

Please note that, there is no `/dev/tcp` or `/dev/udp` folder exists in the system, this redirection mechanism is a feature of the bash shell itself.
