solusipse/fiche

nc alternative (pure bash) (for docs)

datajerk opened this issue · 8 comments

#!/bin/bash

exec 3<>/dev/tcp/termbin.com/9999       # create FD
[ -t 0 ] && echo -en $* >&3 || cat >&3  # send it
cat <&3                                 # get the url
exec 3<&-                               # remove FD (clean up)

Usage:

echo foo bar foo | bashscript

or

bashscript test 123

OS/X and Linux tested.

Alias example:

$ alias tb2="(exec 3<>/dev/tcp/termbin.com/9999; cat >&3; cat <&3; exec 3<&-)"
$ echo foobar | tb2

That's awesome, thanks, I'll add it to the project's website!

Added to the readme, thank you very much!

When executing the above command,

I get this on the client side:

-bash: 3: Bad file descriptor
-bash: 3: Bad file descriptor

And this on the server side:

[Fiche][ERROR] No data received from the client!

@theAkito Perhaps this should fix it for you,

mknod /dev/tcp c 30 36
mknod /dev/udp c 30 39

@theAkito in bash > 4.1 you can use

$ exec {var} > file
$ echo $var
10

fwiw, here is the equipment on zsh

tb() { zmodload zsh/net/tcp; ztcp termbin.com 9999; cat >&$REPLY; cat <&$REPLY; ztcp -c $REPLY }

If I was trying to do something like echo ruok | nc 127.0.0.1 5111 how would I do it with this alias? 🤔

Pure POSIX shell? Anyone? :)