# How to check network switch or computers alive with PING

**URL:** https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405
**Category:** General
**Created:** [22 May 2019 09:24 UTC](https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405 "2019-05-22T09:24:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![muharremsari](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muharremsari/32/7996_2.png) [@muharremsari](https://discourse.nodered.org/u/muharremsari)
#### Post date: [22 May 2019 09:24 UTC](https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405/1 "2019-05-22T09:24:04Z")

</div>

I would get alive signal with PING from net device. I was use [ping-notification](https://github.com/cflurin/node-red-contrib-dsm/wiki/ping-notification) and saw response time on debug monitor.

How i convert response time to BOOLEAN value FALSE or TRUE for "Communication Is Ok"

```auto
[{"id":"b86d0cad.8e96a","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"3cbd49f6.ebdd26","type":"debug","z":"b86d0cad.8e96a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1038,"y":346,"wires":[]},{"id":"f4763647.dd5de8","type":"comment","z":"b86d0cad.8e96a","name":"send a notification e.g. to pushover","info":"","x":699,"y":304,"wires":[]},{"id":"913cd07d.12dbf","type":"ping","z":"b86d0cad.8e96a","name":"","host":"10.67.20.56","timer":"5","x":509,"y":344,"wires":[["3cbd49f6.ebdd26"]]}]

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [22 May 2019 10:01 UTC](https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405/2 "2019-05-22T10:01:03Z")

</div>

You could do this...

```auto
[{"id":"91e689b6.4b5cc8","type":"debug","z":"e0ee1196.5368e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":450,"y":280,"wires":[]},{"id":"a2329b30.c1f468","type":"comment","z":"e0ee1196.5368e","name":"send a notification e.g. to pushover","info":"","x":280,"y":240,"wires":[]},{"id":"d3067bc1.d1da88","type":"ping","z":"e0ee1196.5368e","name":"","host":"10.67.20.56","timer":"5","x":210,"y":280,"wires":[["91e689b6.4b5cc8","9a789de0.45619"]]},{"id":"9a789de0.45619","type":"function","z":"e0ee1196.5368e","name":"Update flow.pingOK","func":"var isOk = (typeof msg.payload == 'number')\nflow.set(\"pingOK\", isOk);\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":320,"wires":[[]]}]

```

---

<div class="post-metadata">

### Author: ![muharremsari](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muharremsari/32/7996_2.png) [@muharremsari](https://discourse.nodered.org/u/muharremsari)
#### Post date: [22 May 2019 11:05 UTC](https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405/3 "2019-05-22T11:05:04Z")

</div>

I can't see "pingOK" Function node out. Sorry i'm a beginner.

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [22 May 2019 14:29 UTC](https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405/4 "2019-05-22T14:29:40Z")

</div>

you probably don't have the node installed. From the manage palette, click the `install` tab and enter `node-red-node-ping` and hit install. Then you can deploy and test it.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [22 May 2019 18:03 UTC](https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405/5 "2019-05-22T18:03:00Z")

</div>

I'm confused.

Was the flow you posted in 1st thread yours?

If so, then I imported it and added a function node to the end to do what you asked, make a true or false., Then exported it and pasted your flow + my mod in my response. In other words, it should work for you as I added nothing more than a standard function node.

I stored the true false result in flow context so you could see it.

You can view flow context variables in the side bar (switch from debug to context)  
E.g...  
[https://images.app.goo.gl/eNAYvB8986x3Xzae8](https://images.app.goo.gl/eNAYvB8986x3Xzae8)

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [22 May 2019 18:36 UTC](https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405/6 "2019-05-22T18:36:33Z")

</div>

From the node's info tab  
`Pings a machine and returns the trip time in mS as msg.payload.`  
`Returns false if no response received within 5 seconds, or if the host is unresolveable.`  
`Default ping is every 20 seconds but can be configured.`  
`msg.topic contains the target host ip.`

So you eithor get a value or `false`.

you can add a line to @Steve-Mcl function node so it looks like this

```auto
var isOk = (typeof msg.payload == 'number');
flow.set("pingOK", isOk);
msg.payload = isOk;
return msg;

```

and you will get true or false in the msg.payload

---

<div class="post-metadata">

### Author: ![muharremsari](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/muharremsari/32/7996_2.png) [@muharremsari](https://discourse.nodered.org/u/muharremsari)
#### Post date: [22 May 2019 18:52 UTC](https://discourse.nodered.org/t/how-to-check-network-switch-or-computers-alive-with-ping/11405/7 "2019-05-22T18:52:58Z")

</div>

Problem solved. Thanks.
