Live data from Hacker News

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

mareksuppa.com

51–60 of 255 posts

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

#51

Earlier quoted context omitted.

example.com is also great for that reason when something fails about a captive portal on a public WiFi. I open my web browser and go to http://example.com and get redirected to the captive portal page again and retry completing what they need from me to get internet access.

Fun fact, this is almost exactly how active portal detection is done in the OS/browser! https://gist.github.com/skull-squadron/edb8c0122f902013304c0...

Yep :) I just find example.com easier to remember and quicker to type than any of the OS or browser makers own URLs like

- http://captive.apple.com/

- http://connectivitycheck.gstatic.com/generate_204

- http://detectportal.brave-http-only.com/

Plus, it feels nice to depend on the reserved domain name example.com instead of relying on a domain that any one specific corporation has to maintain :D

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

#52
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.

It's pretty rough to learn I sound like Claude. Will need to do something about it then.

(For what it's worth I did write the message above manually but I understand why no one would believe that now. At least I did not call netcat "load-bearing" [https://mareksuppa.com/til/load-bearing/] or something...)

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

#54
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…

[flagged]

An old habit that unfortunately makes one indistinguishable from LLMs these days...

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

#56

Earlier quoted context omitted.

Fun fact, this is almost exactly how active portal detection is done in the OS/browser! https://gist.github.com/skull-squadron/edb8c0122f902013304c0...

Yep :) I just find example.com easier to remember and quicker to type than any of the OS or browser makers own URLs like - http://captive.apple.com/ - http://connectivitycheck.gstatic.com/generate_204 - http://detectportal.brave-http-only.com/ Plus, it feels nice to depend on the reserved domain name example.com instead of relying on a domain that any one specific corporation has to maintain :D

Also http://detectportal.firefox.com. And http://neverssl.com was set up for this purpose while being a bit easier to remember :)

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

#57
post #21

Earlier quoted context omitted.

I always recommend to not have any dependencies outside of the code. So we start at compiling the codebase (Rust) against MUSL. That way we can run it with FROM scratch images. If we need more tooling available at runtime, then we look at alpine, but still using MUSL. If MUSL itself is proving problematic, or if some of the libraries we use need glibc then we can look at using some locked down image. The cool part ab…

> The cool part about FROM scratch images is that you'll never have to update your base image to address CVEs. Only your software and its (compiled) dependencies. What's the benefit really, though? If you still need to be able to rapidly deploy a new image in response to a dependency CVE, what have you gained?

If the base image I use is based on Debian, it comes with more than 15 binaries that I don't use.

But when Docker scans my image and notices that there is a CVE in one of those binaries, my image is currently out of compliance.

FROM scratch just reduces the surface.

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

#58
post #17
post #9

Earlier quoted context omitted.

Totally! I was really just trying to see if intra-container connectivity works, and this ended up being a very quick way of doing so. (The alternative being building and deploying a new image, which would likely take significantly longer.)

> The alternative being building and deploying a new image, which would likely take significantly longer You said the image was Python, though? Using that is way easier and faster. https://news.ycombinator.com/item?id=48558763 If all you need to know is that it can connect: python3 -c 'import socket as s;s.create_connection(("8.8.8.8",53))' or http: python3 -c 'from urllib.request import*;print(urlopen(" http://examp…

You are right, I am not sure why I did not realize Python is the whole point of the image. This is indeed much faster and easier.

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

#59
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)

Note: Telnet is not completely plaintext and has control characters in the upper byte range (like 0xff or something, I forget).

Use nc or this TCP Bash technique if you really want to ensure decent compatibility when doing hacky solutions, otherwise a random 0xFF somewhere from a terminal console color change (or other control character) might really screw you over.

EDIT or ya know, use the correct tool like Curl.

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

#60
post #52

Earlier quoted context omitted.

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

It's pretty rough to learn I sound like Claude. Will need to do something about it then. (For what it's worth I did write the message above manually but I understand why no one would believe that now. At least I did not call netcat "load-bearing" [ https://mareksuppa.com/til/load-bearing/ ] or something...)

Ok Claude :)
Post reply on HN