#!/usr/bin/python
import os,sys
import linecache
def config_dhcp(ip_mac_list,dhcp_conf):
all_file = [ x.replace('\n','').split('\t') for x in linecache.getlines(ip_mac_list)]
dhcp_file = open(dhcp_conf,'a')
for items in all_file:
print >>dhcp_file,'host %s {' % items[0]
print >>dhcp_file,''
print >>dhcp_file,' hardware ethernet %s;' % items[2]
print >>dhcp_file,' fixed-address %s;' % items[1]
print >>dhcp_file,'}'
print >>dhcp_file,''
dhcp_file.close()
return 'Config OK!!!!!'
if __name__ == '__main__':
print config_dhcp(sys.argv[1],sys.argv[2])
###################################
#sys.argv[0] hostname IP MAC
###################################
格式: 主机名 IP MAC(mac地址格式 00:00:00:00:00:00) 我是直接从EXCEL 中粘贴到LINUX里面的