-
Notifications
You must be signed in to change notification settings - Fork 0
/
pingtest.py
49 lines (42 loc) · 1.07 KB
/
pingtest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
import os
import sys
import time
import requests
import subprocess
import yaml
from datetime import timedelta
# todo add some checks to the VPN?
import RPi.GPIO as GPIO
import pyping
badping = 0
def RobustPing(dest):
global totalping, badping
ok = False
# todo should make this a loop that tries until success or 10 failures
for i in range(100):
try:
netup = pyping.ping(dest, timeout=5, count=1)
except:
print 'External Ping Exception'
inetup.ret_code = 1 # just assume bad this loop
if netup.ret_code == 0:
ok = True # one success in loop is success
else:
badping = badping + 1
print 'Ping failure to:' + dest + ' ' + str(badping)
#logit('Ping Failure to: ' + dest + ' ''+ str(netup.ret_code) + str(netup.output))
def PingSh(dest):
global badping
null = open('/dev/null','a')
for i in range(100):
cmd = 'ping -c 1 '+dest
p = subprocess.call(cmd,shell=True,stdout=null,stderr=null)
print 'RETURN CODE: ', p
if p <> 0:
badping = badping + 1
RobustPing('8.8.8.8')
print badping
badping = 0
PingSh('8.8.8.8')
print badping