Вот пример скрипта Python (код для большей ясности):
import socket
import re
import sys
ethers_file = open(sys.argv[1],'r')
for line in ethers_file:
values = line.split()
mac = None
ip = None
if len(values) >=1 and re.match( r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$',values[0]) :
mac = values[0]
if len(values) >=2 and re.match( r'^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$',values[1]) :
ip = values[1]
hostname = None
if (mac is not None and ip is not None) :
try:
resolve_values = socket.gethostbyaddr(ip)
hostname = resolve_values[0];
except:
hostname = "host_" + ip.replace("\\.","_")
if (mac is not None and ip is not None) :
print "host " + hostname + " {"
print " hardware ethernet " + mac
print " fixed address " + ip
print "}"
ethers_file.close()