# Using 3rd python library: pyping

**URL:** <https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [July 24, 2018, 3:32pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949 "2018-07-24T15:32:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [July 24, 2018, 3:32pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/1 "2018-07-24T15:32:04Z")

</div>

Hi, I’d like to use the following library  
[https://pypi.org/project/pyping/](https://pypi.org/project/pyping/)  
in my Python scripts. I downloaded the library and got the following files:  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8c21e2c05cdeec501db5c785d4c72c3a2f5b96cb.png)  
where the `pyping` folder containes the `core.py` module with the core functions.  
I tried copying the whole folders structure into the `/user-lib/pylib` ignition folder, but I cannot call any of the library functions and moreover `import pyping` returns an error.  
So: what should I import in order to have that library work in my scripts?

(Ignition version: 7.9.8)

Thanks in advance

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [July 24, 2018, 4:04pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/2 "2018-07-24T16:04:56Z")

</div>

What version of Python does it use? 2.5? 2.7? 3?

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [July 24, 2018, 4:40pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/3 "2018-07-24T16:40:09Z")

</div>

I don’t know really. The only thing I can grasp from the library homepage is the date of the last commit: 2016. But as a general question: is the way I went right to include a 3rd party library?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 24, 2018, 4:41pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/4 "2018-07-24T16:41:28Z")

</div>

I think you’re close: [https://support.inductiveautomation.com/index.php?/Knowledgebase/Article/View/98/2/importing-and-using-3rd-party-python-libraries-in-ignition](https://support.inductiveautomation.com/index.php?/Knowledgebase/Article/View/98/2/importing-and-using-3rd-party-python-libraries-in-ignition)

This library looks to be in Python 3 as well as require root/administrator access to run, so it’s unlikely you’re going to be able to use it.

edit: worth a try if you can get the import working. Looks like you just need the pyping folder and not all the other stuff in the zip. The only reason I have to think it’s Python 3 is because one of the history entries mentions converting to it.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 24, 2018, 4:49pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/5 "2018-07-24T16:49:37Z")

</div>

The other question is “why do you need to ping anything?”

---

<div class="post-metadata">

**Author:** ![mrogers](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mrogers/32/4110_2.png) [@mrogers](https://forum.inductiveautomation.com/u/mrogers)\
**Post date:** [July 24, 2018, 7:12pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/6 "2018-07-24T19:12:41Z")

</div>

Might be able to use something like

```auto
import os
os.system("ping " + hostname)

```

I haven’t done much with that personally but it may be worth some research if you need to ping something.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [July 24, 2018, 9:02pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/7 "2018-07-24T21:02:35Z")

</div>

os.system does not give you any output from the command. I would do either of the following:

1. Use Popen

```auto
from subprocess import Popen,PIPE
p = Popen("ping -n 1 www.google.com",stdout = PIPE)
output,err = p.communicate("")
print output[output.find("time")+5:output.find("TTL")-3]

```

Or  
2. Use a module, depending on your goals

> **[Kymera Systems Inc | IIoT Solutions - Kymera Pinger Driver](https://www.kymerasystems.com/kymera-pinger-driver/)**
>
> Monitor network health, visualize the effects of changing parameters and tweak your setup for the perfectly optimized solution...

---

<div class="post-metadata">

**Author:** ![pgmo](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@pgmo](https://forum.inductiveautomation.com/u/pgmo)\
**Post date:** [July 25, 2018, 6:52am UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/8 "2018-07-25T06:52:25Z")

</div>

Thanks to all for your kind suggestions: I will try all of them.

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [July 31, 2018, 2:06pm UTC](https://forum.inductiveautomation.com/t/using-3rd-python-library-pyping/18949/9 "2018-07-31T14:06:39Z")

</div>

Just augmenting @Kyle_Chase’s good suggestion. You could create a script in your `project` script library called `inetutils`:

```auto
import sys
import re
from subprocess import Popen, PIPE

def ping(host, count=1, timeout=1000):
	if sys.platform == 'win32':
		count_arg = '-n'
		timeout_arg = '-w'
	else:
		count_arg = '-c'
		timeout_arg = '-W'
	
	args = map(str, ['ping', count_arg, count, timeout_arg, timeout, host])
	
	p = Popen(args, stdout=PIPE, stderr=PIPE)
	output, err = p.communicate()
	
	if p.returncode == 0: # success
		try:
			m = re.search("time=(\d+(?:\.\d+){0,1})\s*ms", output)
			time = float(m.group(1))
		except Exception, e:
			time = -1
	else:
		time = None
		
	return (time, p.returncode)

```

Then, in your project, you can use the something like the following:

```auto
from project.inetutils import ping

time, result = ping('google.com')
if result == 0:
	print 'Success, response time is: %.2fms' % time
else:
	print 'Failure, return code: %d' % result

```

The above solution will leverage the return code of the subprocess call, where 0 is a successful result. Other return codes will produce based on various failures of the call to _ping_ such as `68` for unknown host, or `2` for response timeout. Keep in mind that this is still going to be a _blocking_ call, so use accordingly.

Hope this helps!
