Live data from Hacker News

Testing if a port can be reached, using built-in tools other than ol' telnet

carehart.org

81–87 of 87 posts

Re: Testing if a port can be reached, using built-in tools other than ol' telnet

#81
post #72
post #31

Earlier quoted context omitted.

I wish SRV records were more widely adopted, but they are still just a (string -> integer) mapping process above the 16-bit integer values on the wire. Different layers.

And? That's primarily what DNS is for: mapping strings to numbers.

I was just trying to clarify some muddled discussion about different layers of the networking stack. The original comment about port names instead of port numbers didn't seem to be made with an understanding of the different layers.

Re: Testing if a port can be reached, using built-in tools other than ol' telnet

#82
post #55

I’m surprised there is no mention of netcat (nc).

Netcat got replaced by socat, right?

I use socat for serial-line things (like simulating a serial port for unit testing). I didn't occur to me that it can be a netcat replacement.

Re: Testing if a port can be reached, using built-in tools other than ol' telnet

#83
post #74

Earlier quoted context omitted.

> The proposal to use names and not numbers breaks down when you want the rest of the world to follow suit, because it's not technically possible within IP, only on top of IP. This is exactly my point.

> > The proposal to use names and not numbers breaks down when you want the rest of the world to follow suit, because it's not technically possible within IP, only on top of IP. > This is exactly my point. In which case, refer to my original response to your proposal - it's not practical to slow down every networking device in the world by a large factor. It's like asking "why aren't we commuting at 1/3 the speed of…

Surely we can build some protocol on top of IP. I see people mention SRV records. These seem useful, however not very user-friendly at this point, so people don't use them.

Re: Testing if a port can be reached, using built-in tools other than ol' telnet

#84

Ha! This was probably the first serious problem I ever tackled with an open source contribution! The year was 2002, the 2.4 Linux kernel had just been released and I was making money on the side building monitoring software for a few thousand (mostly Solaris) hosts owned by a large German car manufacturer. Everything was built in parallel ksh code, “deployed” to Solaris 8 on Sun E10Ks, and mostly kicked off by cron.…

How is this different from just using netcat?

Netcat even has port scanning capabilities.

Re: Testing if a port can be reached, using built-in tools other than ol' telnet

#85

Kind of unrelated but here's a little bit of bash I use for checking this locally: # Check if the port is available is_port_free() { if [[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -ge 1024 ] && [ "$1" -le 65535 ]; then echo "Valid port number." >&2 else echo "Invalid port number." >&2 return 1 fi if netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ":'$1'$" {exit 1}'; then # Return a truthy value if the port is available return 0 else…

netstat seems to be disappearing from some linux distros - pretty sure it's not on my current Ubuntu by default, so I have to use 'ss' instead (which does seem to be quicker).

Re: Testing if a port can be reached, using built-in tools other than ol' telnet

#86

Earlier quoted context omitted.

that is so cool, my god! Bash is this awesome underrated thing (relative to how I perceive it being used). It's so cool that there's basically a virtual filesystem that maps the internet to your disk...haha. This even works on my Mac. But one issue I encountered was timeout. I just tried: : and it hung. So I asked ChatGPT and it suggested timeout 5 bash -c ':

There isn't a virtual filesystem; bash just pretends there is. You can't use the /dev/tcp path in your own program as it doesn't exist.

Unless...I program in bash! ^^ haha :)

Yeah, I didn't know that. I definitely had a suspicion it was how you say, and "basically" was my fudge word, because I didn't know. I hadn't thought much about it, but I did not know for sure. Thanks for tellin me.

I've thought about this idea: mapping the internet to the Unix filesystem, a la proc. I know TabFS, but I think the mapping could be better.

I think it's an interesting problem to consider what a good mapping would be. But it's all tradeoffs I guess. I haven't thought that much about it. But it did seem interesting.

Maybe not interesting enough to really commit to, because it seemed kinda like a big project. But definitely interesting to consider. What do you think? What kind of mapping would you do?

Re: Testing if a port can be reached, using built-in tools other than ol' telnet

#87

Kind of unrelated but here's a little bit of bash I use for checking this locally: # Check if the port is available is_port_free() { if [[ "$1" =~ ^[0-9]+$ ]] && [ "$1" -ge 1024 ] && [ "$1" -le 65535 ]; then echo "Valid port number." >&2 else echo "Invalid port number." >&2 return 1 fi if netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ":'$1'$" {exit 1}'; then # Return a truthy value if the port is available return 0 else…

netstat seems to be disappearing from some linux distros - pretty sure it's not on my current Ubuntu by default, so I have to use 'ss' instead (which does seem to be quicker).

Cool, thanks for the tip! Yeah, I noticed I had to install netstat some times. Maybe I'll update my scripts to use ss instead. Do you have the conversion? I guess I could ask ChatGPT, but...while you're here? :) heh
Post reply on HN