4 ms·
I'm a zsh user, but one thing I miss from bash is /dev/tcp redirection. ~ echo <>/dev/tcp/google.com/80 ~ echo $? 0 ~ echo <>/dev/tcp/localh
by mattpallissard 4y ago
I'm a zsh user, but one thing I miss from bash is /dev/tcp redirection.
~ echo <>/dev/tcp/google.com/80
~ echo $?
0
~ echo <>/dev/tcp/localhost/80
bash: connect: Network is unreachable
bash: /dev/tcp/localhost/80: Network is unreachable
~ echo $?
1
- softjobs 4y agoWhat about https://zsh.sourceforge.io/Doc/Release/TCP-Function-System.html https://zsh.sourceforge.io/Doc/Release/TCP-Function-System.h...?
- tambourine_man 4y agoI think that’s Linux-only, right?
- ccouzens 4y agoIt's in the /dev/ folder so it looks like a device file provided by the operating system. But it's not. It's a bash built in pseudo file. So it should work in bash on other operating systems.
- hericium 4y agoNice thing to learn - thanks. Although the only scenario I can think of at the moment would be the lack of netcat (and telnet). Not a fan of limiting scripts with bashisms. I like them to be runnable under zsh and similar shells despite having /usr/bin/env bash, /bin/bash, /bin/sh shebang.
- ebfe1 4y agoA more sneaky use case is for reverse shell payload when you have code execution :)
- tambourine_man 4y agoYou're right, it does work on macOS. What other cool use cases could it achieve besides checking if a domain is reachable?
- runjake 4y agoWhy? There’s nc.
- sph 4y agoI tend to prefer telnet to test connections because its output is more verbose. We need a friendlier netcat, with better output. Call it netdog.
- runjake 4y agonc generally provides more verbosity with -v and other options. nc -v itself is pretty much telnet as far as TCP connections go (TELNET is itself another protocol on top of TCP). In fact on macOS, I alias telnet=’nc -v’. Anyway my intent wasn’t to directly challenge your method, this is just a more shell-independent and universal method of doing the same.
- tux2bsd 4y agoThanks. I've not seen that before, that's cool.