Ping a port to check if device is online

Need to “ping” an IP on a specific port and get if the host is responding or not on that particular port.
For example I would like to ping something like 192.168.0.10 on port 15000.
Is there any integration other than https://www.home-assistant.io/integrations/ping/?
That one does not allow you to specify the port so it won’t work

Ping doesn’t work on ports.

What kind of service is running on that port? If it’s a web service of some sort, you can curl the response looking for a “200”

If I could use nmap to probe the port that would do it (that’s how I test from Windows)
Need to probe a konnected board on a particular port to determine if it is up or not

Simple ping will tell you if the board is up.

Try using Putty and configure connection with the port number. If the port is correctly configured and listening you should connect but will not get any response. Port not working you will get a connection refused.

It is confusing whether you are testing if the host is up, or if yoiu are testing a particular port is open.

A commandline sensor using telnet will do the latter.

Unfortunately it will not because it can ping ok and have the port 15000 not responding for example so I need to probe that port and get a reply for it to be 100% it is up. The windows command line version of nmap allows me to do that so I need something similar

This sounds like what I need, how do I set up that guy?

Here you go: https://www.home-assistant.io/integrations/sensor.command_line/

Thanks but do I have to install a telnet addon for this to work?
I assume HASSIO does not have telnet built in since I can’t seem to run it via putty

It should have telnet, but I am sure it has nmap.

Could you please assist me with the syntax? That command line integration link does not have any examples of telnet and a search wasn’t too helpful either. Thx

Its possible when your target-port is a tcp-port. And almost all ports a running over tcp (http, ssh, ftp, smtp, …).

What you want is not a ping (it runs over ICMP and this “portless”).
But you can send a tcp “SYN” and wait for an “SYN ACK” - it should be returned immediately.
btw this is how nmap checking for open ports.

I dont know much about home assistant (Iam HA-newbie), but you can play around with nmap- and/or nc-command (netcat). If not, I can write a small bash-script in the next days.

If windows nmap works why not use nmap in linux?

Also I learned a neat trick when researching this. You can do the following:

echo > /dev/tcp/host/port

for example the machine 192.168.178.254 on my lan runs a web server on port 80, but nothing on port 81.

nick@server:~$ echo > /dev/tcp/192.168.178.254/80
nick@server:~$ echo > /dev/tcp/192.168.178.254/81
-bash: connect: Connection refused
-bash: /dev/tcp/192.168.178.254/81: Connection refused

You can script that easy enough.

Credit due: Test if telnet port is active within a shell script - Unix & Linux Stack Exchange

That would the job alright but since I’m running Hassio on a pi 4 I don’t think you can just run any linux command.
I don’t think telnet is part of it for example and neither does the /dev/tcp command above.

Have you actually tried

echo > /dev/tcp/ip-address/15000 

to your device, or are you just assuming it won’t work?

Doesn’t give any output but if I use wrong port (21080) it does say refused

core-ssh:~# echo > /dev/tcp/192.168.0.100/21081
core-ssh:~# echo > /dev/tcp/192.168.0.100/21080
-bash: connect: Connection refused
-bash: /dev/tcp/192.168.0.100/21080: Connection refused

Still not exactly sure how I can use that in my automation unless it is in a binary sensor or something similar

Please don’t post photos of your text. They have this thing called copy and paste.

Try this as a commandline sensor

# Example configuration.yaml entry
sensor:
  - platform: command_line
    name: Konnected Up
    command:  (echo > /dev/tcp/192.168.x.x/15000) > /dev/null 2>&1 && echo "true" || echo "false"

1 Like

Thanks for that just tried it but looks like this::
image
I wonder if it needs extra single quotes?
I can confirm via putty I get true which means it does work but HA sensor reports it as false
And how often does this check? Just once when HA server is starting? I would need this be run every hour