# Script to ping computer

**URL:** <https://forum.inductiveautomation.com/t/script-to-ping-computer/16612>\
**Category:** Ignition\
**Created:** [January 16, 2018, 6:27pm UTC](https://forum.inductiveautomation.com/t/script-to-ping-computer/16612 "2018-01-16T18:27:35Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![tyler.bennett](https://avatars.discourse-cdn.com/v4/letter/t/f04885/32.png) [@tyler.bennett](https://forum.inductiveautomation.com/u/tyler.bennett)\
**Post date:** [February 10, 2023, 2:27am UTC](https://forum.inductiveautomation.com/t/script-to-ping-computer/16612/19 "2023-02-10T02:27:47Z")

</div>

Here is a lengthy recap of the steps that lead to success in using `java.net` (`InetAddress`, `isReachable`) on a Linux server (Ubuntu 20.04.5 LTS) with Ignition running as a non-root system user account.

1. Ran this command...

```auto
sudo systemctl edit Ignition-Gateway.service

```

> [@Change the user running the Ignition Gateway service](https://forum.inductiveautomation.com/t/change-the-user-running-the-ignition-gateway-service/68564/6):
>
> This will create an override file at `/etc/systemd/system/Ignition-Gateway.service.d/override.conf` that will persist through an Ignition upgrade (that may reset/revert that base configuration file).

1. Added this text... then saved changes.

```auto
[Service]
AmbientCapabilities=CAP_NET_RAW CAP_NET_BIND_SERVICE

```

> [@Change the user running the Ignition Gateway service](https://forum.inductiveautomation.com/t/change-the-user-running-the-ignition-gateway-service/68564/3):
>
> Consider specifying `AmbientCapabilities=CAP_NET_RAW CAP_NET_BIND_SERVICE` to allow Ignition to use ports 80 & 443 and to use built-in ping when not root.

1. Restarted the Ignition gateway...

```auto
sudo /usr/local/bin/ignition/gwcmd.sh -r

```

1. Confirmed the service was running without error

```auto
sudo systemctl status Ignition-Gateway.service

```

1. Confirmed the new settings appeared in the service configuration

```auto
sudo systemctl show Ignition-Gateway.service | grep AmbientCapabilities

```

At this point the `InetAddress` `isreachable` function was still not returning any positive results (all fails).  
I noticed that the results of the `systemctl status Ignition-Gateway.service` command was not showing a recent start date so the `gwcmd.sh -r' command must not have operated at the systemd service level...

1. Restarted the Ignition Gateway service using `systemctl`

```auto
sudo systemctl restart Ignition-Gateway.service

```

Then the `isReachable` function **finally** started returning positive results (successful pings).

For completeness here is my version of the ping function:

```python
	def ping(host, timeout=2000):
		from java.net import InetAddress 
		# (https://docs.oracle.com/javase/8/docs/api/java/net/InetAddress.html) 	
		ip = InetAddress.getByName(host)
		data = { 
			'isReachable':ip.isReachable(timeout)
			,'hostAddress':ip.getHostAddress()
			,'hostName':ip.getHostName()
		}
		return data
	result = ping('8.8.8.8')

```

Thanks to @silverbacknet , @pturmel and @kcollins for your forum posts that helped me sort this out.  
Now to see if I can do similar in a docker container.

---

_[View the full topic](https://forum.inductiveautomation.com/t/script-to-ping-computer/16612)._
