Let's say I just want to search a dhcpd file for host entries, their IP and MAC, and print them in one line. Here, I want some help with a python script. I can able to find the IP address and hostname but I don't know how to get the variables out of the if statement to put it in one line. Look at the below code and give me some suggestions guys?
#!/usr/bin/python
import sys
import re
#check for arguments
if len(sys.argv) > 1:
print "usage: no arguments required"
sys.exit()
else:
dhcp_file = open("/etc/dhcp/dhcpd.conf","r")
for line in dhcp_file:
if re.search(r'\bhost\b',line):
split = re.split(r'\s+', line)
print split[1]
if re.search(r'\bhardware ethernet\b',line):
ip = re.split(r'\s+',line)
print ip[2]
dhcp_file.close()