Skip to content

Commit

Permalink
Add the ability to track DNS Server and DHCP Server, related #7
Browse files Browse the repository at this point in the history
  • Loading branch information
okanozdemir committed May 23, 2018
1 parent e149f0f commit 0adfcc8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
28 changes: 27 additions & 1 deletion kripton-guard/kripton-guard
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ def saveMACs():
query = "INSERT INTO servers (macAddress, ipAddress, name) VALUES ('{0}','{1}','router');".format(getMac(routerIP),routerIP)
conn.execute(query)
conn.commit()
if(dns_server == "yes"):
DNSServerIP = getDNSServer()
query = "INSERT INTO servers (macAddress, ipAddress, name) VALUES ('{0}','{1}','DNSServer');".format(getMac(DNSServerIP),DNSServerIP)
conn.execute(query)
conn.commit()
if(dhcp_server == "yes"):
DHCPServerIP = getDHCPServer()
query = "INSERT INTO servers (macAddress, ipAddress, name) VALUES ('{0}','{1}','router');".format(getMac(DHCPServerIP),DHCPServerIP)
conn.execute(query)
conn.commit()

for option in config.options("CUSTOMSERVERS"):
if(option != ""):
Expand Down Expand Up @@ -131,11 +141,20 @@ def checkServers(server,ip):
sendNotification("'{0}'MACChanged".format(server))

def getGateway():
import subprocess, shlex
strs = subprocess.check_output(shlex.split('ip r l'))
gateway = strs.decode().split('default via')[-1].split()[0]
return gateway

def getDNSServer():
strs = subprocess.check_output(shlex.split('nmcli dev show'))
DNSServer = strs.decode().split('DNS[1]:')[-1].split()[0]
return DNSServer

def getDHCPServer():
strs = subprocess.check_output(shlex.split('dhclient -v'))
DHCPServerIP = strs.decode().split('from')[-1].split()[0]
return DHCPServerIP

if(config['SETTINGS']['first-time']=='1'):
config['SETTINGS']['first-time']='0'
with open('/etc/kripton-guard/kripton-guard.conf','w') as configfile:
Expand All @@ -148,6 +167,13 @@ else:
if(router == "yes"):
routerIP = getGateway()
checkServers("router", routerIP)
if(dns_server == "yes"):
DNSServerIP = getDNSServer()
checkServers("DNSServer", DNSServerIP)
if(dhcp_server == "yes"):
DHCPServerIP = getDHCPServer()
checkServers("DHCPServer", DHCPServerIP)

for option in config.options("CUSTOMSERVERS"):
if(option != ""):
ip = config["CUSTOMSERVERS"][option]
Expand Down
3 changes: 2 additions & 1 deletion kripton-guard/kripton-guard.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ password = YOUR_PASSWORD
repeat-time = 1

[SERVERS]
# Select the servers you want to check (yes or no):
router = yes
dhcp-server = no
dns-server = no

[CUSTOMSERVERS]
#Type in the servers you want to monitor. Example: name = ip
#Type in the servers you want to check. Example: name = ip
#xxxServer = 192.168.20.20

[API]
Expand Down

0 comments on commit 0adfcc8

Please sign in to comment.