Server-Monitoring-Scripts/scripts/DHCP.py

27 lines
779 B
Python

#!/usr/bin/python3
import sys
import re
import subprocess
from lib import bcolor
bcolors = bcolor.bcolors
regex = r"inet ((([0-9]{1,3}.){4})(\/){0,1}([0-9]{0,2}))"
INTERFACE=sys.argv[1]
DHCP=sys.argv[2]
RET=""
INTERFACE_DUMP = subprocess.run(["ip", "a" ,"show","dev",INTERFACE],stdout=subprocess.PIPE, text=True)
matches = re.search(regex, INTERFACE_DUMP.stdout)
if DHCP == "yes":
if matches:
print(bcolors.BOLD + bcolors.OKCYAN+"[CONFIG - NETWORK]"+bcolors.ENDC+" found IP address on "+INTERFACE+".")
else:
print(bcolors.BOLD + bcolors.FAIL+"[CONFIG - NETWORK]"+bcolors.ENDC+" got no IP address, run dhclient on "+INTERFACE+"!")
else:
print(bcolors.BOLD + bcolors.WARNING+"[CONFIG - NETWORK]"+bcolors.ENDC+" no DHCP active in configuration!")