Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nc alternative (pure bash) (for docs) #43

Closed
datajerk opened this issue Jul 16, 2016 · 8 comments
Closed

nc alternative (pure bash) (for docs) #43

datajerk opened this issue Jul 16, 2016 · 8 comments

Comments

@datajerk
Copy link

datajerk commented Jul 16, 2016

#!/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
@solusipse
Copy link
Owner

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

@solusipse
Copy link
Owner

Added to the readme, thank you very much!

@theAkito
Copy link

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!

@Aeres-u99
Copy link

@theAkito Perhaps this should fix it for you,

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

@iddoeldor
Copy link

@theAkito in bash > 4.1 you can use

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

@dashezup
Copy link

dashezup commented Nov 8, 2020

fwiw, here is the equipment on zsh

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

@caleb15
Copy link

caleb15 commented May 12, 2022

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

@martin-braun
Copy link

Pure POSIX shell? Anyone? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants