Live data from Hacker News

TIL: You can make HTTP requests without curl using Bash /dev/TCP

mareksuppa.com

211–220 of 255 posts

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#211

As a kid in the late 90s my mind was blown when I realized I could telnet to port 80, 25, or 110 and interact with the servers manually. Simple get: GET / HTTP/1.1 Content-Type: text/html User-Agent: l33t hax0rs lol X-Funny-Monkey: farts For sending a mail message on port 25: HELO mail-from: whoever@whatever.com mail-to: sysadmin@yaya.com Body of the message yay. POP3 was so long ago I forgot but you could list the m…

HELO is for SMTP, EHLO for ESMTP. You could access some “advanced” features of the server if you told it you speak ESMTP.

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#212

This is pretty neat if all you need is to ping a local server but please use curl (or something equivalent) for contacting remote services. HTTP1.1 seems like such a simple protocol but in the real world you need to deal with proxies, different encodings, and redirects. Curl takes care of that (and a host of other annoying stuff) for you.

[flagged]

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#215
post #12

Earlier quoted context omitted.

> No, it can not. Bash lets you open TCP sockets. Very fair pushback -- I did get carried away and will update the article to be more precise. Thanks for raising it! > For less insane, non-bash shells there is always nc which is usually probably the wiser choice. For completeness, `nc` or any netcat equvialent I could think of was not available in the image I was trying this with. It would certainly be a better optio…

This is the most Claude pilled comment I've seen here.

I’m torn. It’s a great thing to share knowledge and take feedback graciously. Maybe this kind of comment will encourage more of that. But you also need people to tell you what is up without unnecessary filters. It’s a challenge

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#216
post #204
post #73

Earlier quoted context omitted.

Last century I would read and send personal email from work using telnet to pop3 and smtp respectively.

I also have a tendency to say "Last century", thinking it comedically suggests "a long time ago" without it actually being that long ago. But as time goes by it obviously becomes legitimately a long time ago, and I suspect young people wouldn't see the attempted irony at all.

'last century' 'turn of the century' etc just make me think the 1800s. So I just say last millennium.

Probably get confusing again when people start referring to 'the 20s' not as the 1920s.

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#217
post #76

> As it turns out, bash can speak HTTP by itself. No, it can not. Bash lets you open TCP sockets. What you are doing here is trying to speak HTTP yourself, which is fine for testing and debugging, and hella cool for fun to do by hand, but you will shoot yourself in the foot if you try to use this pseudo http client unattended in reality. This toy code does not parse HTTP properly and will break. You could of course w…

Need to be clear that "full http server in pure bash" is incorrect. Bash cannot listen on a TCP/UDP socket for incoming connections. bash-web-server project builds a C language socket listener [0] that is dynamically loaded at run-time as a "built-in" module that makes the functionality available. [0] https://github.com/bahamas10/bash-web-server/tree/main/loada...

This feature has been part of bash since 5.1 (ca 2020), though it may not be enabled in all distros.

  cd src/bash-5.3/examples/loadables
  make accept
  enable -f ./accept accept
  (accept -r RHOST -v SOCKETFD -b 127.0.0.1 8000; 
    read -u $SOCKETFD SOCKETDATA; 
    printf "%s: %s\n" "$RHOST" "$SOCKETDATA";
    printf "goodbye, world\n" 1>&${SOCKETFD} ) &
  nc 127.0.0.1 8000 
For real use you may need to add "exec {SOCKETFD}Edit: https://news.ycombinator.com/item?id=39369749 (2024)

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#218
> This is a bash feature, not POSIX. dash (Debian’s /bin/sh) and zsh don’t have it, so a #!/bin/sh script can’t use it. Call bash directly.

Zsh has its own zsh/net/tcp and zsh/zftp modules.

https://zsh.sourceforge.io/Doc/Release/TCP-Function-System.h...

https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#The-...

https://zsh.sourceforge.io/Doc/Release/Zftp-Function-System....

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#219
post #50

Earlier quoted context omitted.

Why wouldn’t you use curl for the quick test?

because in those days there was no curl, or wget. and then when there was, there was no guarantee they'd be installed. telnet was always there though. it also worked for speaking all the other plaintext internet protocols. (imap, pop, smtp, etc)

In the days of ultra thin containers, there's still no guarantee curl or wget will be installed, either.

Re: TIL: You can make HTTP requests without curl using Bash /dev/TCP

#220
post #206

Earlier quoted context omitted.

The magic for me, to this day in fact, is knowing that mail is essentially anyone on the internet being allowed to write to a mail servers disk. There are rules now, but the concept is still almost intact, random people writing to the servers disk - to be later read by someone

It used to be even more literally so - network mail started off as using FTP to SNDMSG onto a remote system instead of your own. In RFC475, FTP has MAIL and MLFL (mailfile) commands to support this. I think it's neat that you can still find echoes of this. MAIL worked by just appending to MLFL, separating records with CRLF.CRLF - which is still how Data segments are terminated in SMTP.

Was that before or after UUCP? I know that UUCP carried a command in each message, so you would specify a message body with a tag that says pass it to the mail receiving peogram.
Post reply on HN