-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathping.py
More file actions
33 lines (25 loc) · 1.03 KB
/
ping.py
File metadata and controls
33 lines (25 loc) · 1.03 KB
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
import os
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import datetime
hostname = ['192.168.1.1','192.168.1.3','192.168.1.102','192.168.1.13','192.168.1.98'] #list of ip's
now=datetime.datetime.now()
#and then check the response...
for nw in hostname:
response = os.system("ping -c 1 " + nw)
if response != 0:
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "NETWORK DOWN"
body = "%r IS DOWN AT" % nw + " " + now.strftime("%Y-%m-%d %H:%M")
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, "Amma@1994")
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()