-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyPing_native.py
59 lines (46 loc) · 1.31 KB
/
pyPing_native.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
50
51
52
53
54
55
56
57
58
59
#!python3
from datetime import datetime
import subprocess
import time
import logging
##########
#Startup
##########
print('Input target URL / IP!')
target=input()
print('Pinging to '+target)
##########
#setup logging
##########
logging.basicConfig(filename=target+'.log',format='%(asctime)s - %(message)s',level=logging.INFO)
##########
#Process reference
##########
#output = pingProc.stdout
#outErr = pingProc.stderr
#TraceRoute output
#tOutput = traceProc.stdout
#tOutErr = traceProc.stderr
#print(output,outErr)
#print(tOutput,tOutErr)
##########
#The Loop!
##########
currentTime=datetime.now().hour
print('Hour:',currentTime)
while True:
time.sleep(1)
if currentTime != datetime.now().hour:
currentTime=datetime.now().hour
print('\nHour:',currentTime)
pingProc = subprocess.run(["ping",target,"-n","1"],encoding='utf-8',stdout=subprocess.PIPE,stderr=subprocess.PIPE)
if 'Request timed out.' in pingProc.stdout:
logging.warning('Ping to '+target+' failed!')
print('!',flush=True, end="")
#traceProc = subprocess.run(["tracert",target],encoding='utf-8',stdout=subprocess.PIPE,stderr=subprocess.PIPE)
#logging.warning(traceProc.stdout)
#print('!')
else:
print('.',flush=True, end="")
time.sleep(3)
#print('.')