-
Notifications
You must be signed in to change notification settings - Fork 0
/
Host_discovery.py
78 lines (67 loc) · 1.94 KB
/
Host_discovery.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import mysql.connector
import socket
from tkinter import messagebox as mb
from ping3 import ping
from itertools import count
import datetime
import matplotlib.animation as animation
import matplotlib.pyplot as plt
from matplotlib import style
global IP,IP1
mydb4 = mysql.connector.connect(
host="localhost",
user='yashaskm11',
password='4747',
database='Netmonk'
)
mycursor4 = mydb4.cursor()
dates = []
res = []
lis = []
index = count()
style.use('fivethirtyeight')
def start(ip):
IP1
IP=ip
mycursor4.execute('truncate pingtime')
ani = animation.FuncAnimation(plt.gcf(), animate, interval='5000')
plt.tight_layout()
plt.show()
def animate(i):
if i==0:
global lis,res
res=list()
lis=list()
else:
plt.cla()
pinging(IP)
mycursor4.execute('Select res,time from pingtime where ip=(%s)', (IP,))
resp = mycursor4.fetchall()
res.append(float(resp[i][0]))
lis.append(resp[i][1])
plt.xlabel("Time")
plt.ylabel("Resposne time in milliseconds")
plt.title("Response time of "+str(IP1))
plt.plot(lis, res)
i += 1
def pinging(ip):
res = ping(ip, unit='ms')
timestamp = datetime.datetime.now()
pushtodb((ip, res, timestamp))
def pushtodb(val):
sql = "INSERT INTO pingtime VALUES (%s,%s,%s)"
mycursor4.execute(sql, val)
mydb4.commit()
def Diagnose():
try:
sock = socket.create_connection(("www.github.com", 80))
if sock is not None:
sock.close()
mb.showinfo('Internet Diagnose Tool', 'You are successfully connected to Internet')
except OSError:
try:
sock =socket.create_connection(('8.8.8.8',53))
if sock is not None:
mb.showwarning("Internet Diagnose Tool","You are connected to Internet, Check for DNS Issues")
except:
mb.showerror("Internet Diagnose Tool","You are not connected to Internet, Check your Router or Contact your ISP")