Using nc command in a program?

(Using ESP, Wemos D1 Mini)

I have a small PCB that I made to monitor the status of the servers on my LAN. Basically, if the server is online, I get a green LED. If not, I get a red LED. I am currently using the EPSPing.h library to test if the servers on my LAN, but it is not fast nor reliable. So, I would like to replace ping.

I am finding that using the command line "nc -z -w 3 192.168.1.124 1830" is a lot faster than ping and I haven't received a false response in my testing.

Is there a way that I can run this command line from my program and get the response code (if there is one)?

Alternately, is there a way to test a port of another computer on my LAN?

nc runs the netcat program (a network analysis tool).

I know that. The question was how do I run nc from my program?

The same way you would run any external program. Your program issues a command to the operating system to load and execute that separate program.

Have you even checked how netcat has been implemented for ESP32/RTOS?

Which I can't find.... It's not something I have done before and a Google search is not helpful.

I don't use RTOS and I already said that my board is an ESP8266 (Wemos D1 Mini). If your only help is to tell me to read the docs, then at least provide a link to the docs that I can't find.

You forgot to mention which system was running this command. It was certainly not the ESP32.

I've not seen a reference to something like netcat for the ESP32, and there is no built in command line interpreter. Nor am I aware of any implementation that allows loading and running several independent programs on ESP32.

It is possible to have one program execute independent tasks using RTOS, but I'm not interested in doing the research to determine whether netcat has been implemented. That would be your job.

As an aside, ping is very, very fast and reliable on modern operating systems. There may be something wrong with the ESP32 implementation, or you are using it incorrectly.

WiFiClient.connect(IPAddress(192,168,1,124), 1830, 3000)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.