{"id":337068,"date":"2022-08-15T15:00:48","date_gmt":"2022-08-15T15:00:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=337068"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=337068","title":{"rendered":"<span>\u041a\u0430\u043a \u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u043b \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 DHCP \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Excel \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 Python<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c DHCP \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Linux, \u043d\u043e \u0431\u044b\u043b\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0431\u044b\u043b\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e DHCP \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (\u0432\u0441\u0435 ip \u0431\u044b\u043b\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438), \u043a\u0430\u0440\u0442\u044b \u0441\u0435\u0442\u0438, \u0441\u043f\u0438\u0441\u043a\u0430 ip \u0438 mac \u0430\u0434\u0440\u0435\u0441\u043e\u0432. \u042f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0441\u043f\u0438\u0441\u043e\u043a mac \u0438 ip, \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u043b \u0438 \u043c\u044b \u0441 \u043a\u043e\u043b\u043b\u0435\u0433\u043e\u0439 \u043f\u043e\u0448\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \u0442\u0435\u0445, \u0443 \u043a\u043e\u0433\u043e \u044d\u0442\u0438 mac \u0430\u0434\u0440\u0435\u0441\u0430. \u041f\u043e\u0442\u043e\u043c \u044f \u0432\u043d\u0435\u0441 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 excel (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 1). <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"5\" data-colwidth=\"0,140,140,0,0\" width=\"0\">\n<p align=\"center\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041a\u0430\u0431\u0438\u043d\u0435\u0442<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"left\">\u0418\u043c\u044f \u041f\u041a<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"left\">\u0424\u0418\u041e<\/p>\n<\/td>\n<td>\n<p align=\"left\">IP<\/p>\n<\/td>\n<td>\n<p align=\"left\">MAC<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p>1-1<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"left\">\u0418\u0432\u0430\u043d\u043e\u0432 <br \/>\u0418\u0432\u0430\u043d<br \/>\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447<\/p>\n<\/td>\n<td>\n<p align=\"left\">192.168.0.10<\/p>\n<\/td>\n<td>\n<p align=\"left\">00:00:00:00:00:00<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u043e\u043b\u0433\u043e\u0434\u0430 \u0441\u043f\u0443\u0441\u0442\u044f \u044f \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0440\u0435\u0448\u0438\u043b \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 DHCP \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0414\u043b\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f ip \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0435 \u0432 config. \u041d\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 75 \u0441\u0442\u0440\u043e\u043a \u0441 mac, ip, \u0444\u0430\u043c\u0438\u043b\u0438\u044f\u043c\u0438, \u0431\u044b\u043b\u043e \u043a\u0430\u043a-\u0442\u043e \u043b\u0435\u043d\u044c \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0435 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c python \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430 dhcp.conf:<\/p>\n<pre><code>host Lastname { hardware ethernet 00:00:00:00:00:00; fixed-address 192.168.0.1; }<\/code><\/pre>\n<ul>\n<li>\n<p><strong>Lastname <\/strong>&#8212; \u0424\u0430\u043c\u0438\u043b\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>hardware ethernet <\/strong>&#8212; MAC \u0430\u0434\u0440\u0435\u0441.<\/p>\n<\/li>\n<li>\n<p><strong>fixed-address<\/strong> &#8212; ip \u0430\u0434\u0440\u0435\u0441 \u0434\u043b\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043a\u0443\u0449\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043b\u0430 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0424\u0418\u041e \u0432 \u043d\u0435\u0439 \u043f\u043e\u043b\u043d\u043e. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 2) \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043b \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \u043d\u0430 \u043b\u0430\u0442\u0438\u043d\u0438\u0446\u0443.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">name<\/p>\n<\/td>\n<td>\n<p align=\"left\">mac<\/p>\n<\/td>\n<td>\n<p align=\"left\">ip<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Ivanov<\/p>\n<\/td>\n<td>\n<p align=\"left\">00:00:00:00:00:00<\/p>\n<\/td>\n<td>\n<p align=\"left\">192.168.0.10<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044f \u043d\u0430\u0447\u0430\u043b \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 python, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c 3 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430.<\/p>\n<blockquote>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <strong>xlrd<\/strong> \u0438 <strong>pandas<\/strong> 1\u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 excel \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0447\u0438\u0442\u0430\u044f \u0435\u0435 \u043e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432.<\/p>\n<\/blockquote>\n<hr\/>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1<\/h3>\n<p>\u0425\u043e\u0442\u0435\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 pandas \u043d\u043e \u043e\u043d\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u043b\u0430\u0441\u044c \u0438 \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043a\u0438. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0441\u043a\u043e\u0431\u043a\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c excel. \u0421 \u043f\u0440\u043e\u0442\u044f\u0436\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b.<\/p>\n<pre><code>=\"'\"&amp;A1&amp;\"',\" - \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 name =\"'\"&amp;B1&amp;\"',\" - \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 mac =\"'\"&amp;C1&amp;\"',\" - \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 ip<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0442\u0430\u043a (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 3).<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">name<\/p>\n<\/td>\n<td>\n<p align=\"left\">mac<\/p>\n<\/td>\n<td>\n<p align=\"left\">ip<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8216;Ivanov&#8217;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8217;00:00:00:00:00:00&#8242;,<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8216;192.168.0.10&#8217;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u043d\u0435\u0441 \u044d\u0442\u043e \u0432\u0441\u0435 \u0432 \u0441\u043f\u0438\u0441\u043a\u0438 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u043b\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c.<\/p>\n<pre><code class=\"python\">mac=['00:00:00:00:00:00', ...] ip=['192.168.0.10', ...] name=['Ivanov', ...]  def write():     with open(\"dhcp.conf\", 'w') as f:         for i,j,k in zip(Config.name, Config.mac, Config.ip):             f.write(f\"host {i}\" + \" {\\n\\thardware ethernet\" + f\" {j};\" + \"\\n\\tfixed-address \" + f\"{k};\" + \"\\n}\\n\\n\")  if __name__ == '__main__':     write()<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c 3 \u0441\u043f\u0438\u0441\u043a\u0430:<\/p>\n<ul>\n<li>\n<p><strong>mac<\/strong> &#8212; \u0434\u043b\u044f mac \u0430\u0434\u0440\u0435\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>ip<\/strong> -\u0434\u043b\u044f ip \u0430\u0434\u0440\u0435\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>name<\/strong> &#8212; \u0434\u043b\u044f \u0444\u0430\u043c\u0438\u043b\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">mac=['00:00:00:00:00:00', ...] ip=['192.168.0.10', ...] name=['Ivanov', ...]<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def write():<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b dhcp.conf \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0437\u0430\u043f\u0438\u0441\u0438:<\/p>\n<pre><code class=\"python\">with open(\"dhcp.conf\", 'w') as f:<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0430\u043c. <strong>zip<\/strong> &#8212;  \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0438\u0437 \u043d\u0438\u0445 \u0441\u043f\u0438\u0441\u043e\u043a (\u043a\u043e\u0440\u0442\u0435\u0436):<\/p>\n<pre><code class=\"python\">for i,j,k in zip(Config.name, Config.mac, Config.ip):<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\">f.write(f\"host {i}\" + \" {\\n\\thardware ethernet\" + f\" {j};\" + \"\\n\\tfixed-address \" + f\"{k};\" + \"\\n}\\n\\n\")<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     write()<\/code><\/pre>\n<hr\/>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2<\/h3>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 2 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 xlrd.<\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 xlsx \u0444\u043e\u0440\u043c\u0430\u0442 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 xls.<\/p>\n<pre><code class=\"python\">import xlrd  def write():     loc = (r\"C:\\path\\to\\file\\filename.xls\")     sheet = xlrd.open_workbook(loc).sheet_by_index(0)     with open(\"dhcp.conf\", 'w') as f:         for i in range(sheet.nrows):             f.write(f\"host {sheet.cell_value(i, 0)}\" + \" {\\n\\thardware ethernet\" + f\" {sheet.cell_value(i,1)};\" + \"\\n\\tfixed-address \" + f\"{sheet.cell_value(i,2)};\" + \"\\n}\\n\\n\")              if __name__ == '__main__':     write()<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">import xlrd<\/code><\/pre>\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def write():<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c excel \u0438 \u043b\u0438\u0441\u0442 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c 0:<\/p>\n<pre><code class=\"python\">loc = (r\"C:\\path\\to\\file\\filename.xls\") sheet = xlrd.open_workbook(loc).sheet_by_index(0)<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">sheet = xlrd.open_workbook(r\"C:\\path\\to\\file\\filename.xls\").sheet_by_index(0)<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<pre><code class=\"python\">with open(\"dhcp.conf\", 'w') as f:<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0441\u0442\u0440\u043e\u043a. \u0413\u0434\u0435 &#8216;<strong>sheet.nrows&#8217;<\/strong> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"python\"> for i in range(sheet.nrows):<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0444\u0430\u0439\u043b. <strong>sheet.cell_value(i, 0) <\/strong>&#8212; \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043b\u044f \u0433\u0434\u0435 <strong>i <\/strong>&#8212; \u0441\u0442\u0440\u043e\u043a\u0430, <strong>0<\/strong> &#8212; \u0441\u0442\u043e\u043b\u0431\u0435\u0446:<\/p>\n<pre><code class=\"python\">f.write(f\"host {sheet.cell_value(i, 0)}\" + \" {\\n\\thardware ethernet\" + f\" {sheet.cell_value(i,1)};\" + \"\\n\\tfixed-address \" + f\"{sheet.cell_value(i,2)};\" + \"\\n}\\n\\<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     write()<\/code><\/pre>\n<hr\/>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3<\/h3>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 2 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 pandas.<\/p>\n<pre><code class=\"python\">import pandas as pd  def write():     excel = pd.read_excel(r'C:\\path\\to\\file\\filename.xlsx')     with open(\"dhcp.conf\", 'w') as f:         for i, j, k in zip(excel[\"Name\"].tolist(), excel[\"MAC\"].tolist(), excel[\"IP\"].tolist()):              f.write(f\"host {i}\" + \" {\\n\\thardware ethernet\" + f\" {j};\" + \"\\n\\tfixed-address \" + f\"{k};\" + \"\\n}\\n\\n\")      if __name__ == '__main__':     write()<\/code><\/pre>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. <strong>as<\/strong> &#8212; \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u0430:<\/p>\n<pre><code class=\"python\">import pandas as pd<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def write():<\/code><\/pre>\n<p>\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 excel:<\/p>\n<pre><code class=\"python\">excel = pd.read_excel(r'C:\\path\\to\\file\\filename.xlsx')<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">with open(\"dhcp.conf\", 'w') as f:<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0430\u043c:<\/p>\n<pre><code class=\"python\">for i, j, k in zip(excel[\"Name\"].tolist(), excel[\"MAC\"].tolist(), excel[\"IP\"].tolist()):<\/code><\/pre>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 &#8216;Name&#8217;, &#8216;mac&#8217;, &#8216;ip&#8217;. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0437 \u043d\u0438\u0445 \u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<pre><code class=\"python\">excel[\"Name\"].tolist(), excel[\"MAC\"].tolist(), excel[\"IP\"].tolist<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a pandas \u0432\u0438\u0434\u0438\u0442 \u043e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435 excel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430:<\/p>\n<pre><code class=\"python\">print (excel.columns.ravel())<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\">f.write(f\"host {i}\" + \" {\\n\\thardware ethernet\" + f\" {j};\" + \"\\n\\tfixed-address \" + f\"{k};\" + \"\\n}\\n\\n<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     write()<\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434 \u0432\u0441\u0435\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0432 dhcp.conf:<\/p>\n<pre><code>host Ivanov { hardware ethernet 00:00:00:00:00:00; fixed-address 192.168.0.10; }<\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e.<\/p>\n<p>PS: \u044d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/682558\/\"> https:\/\/habr.com\/ru\/post\/682558\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042f \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c DHCP \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Linux, \u043d\u043e \u0431\u044b\u043b\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430, \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0431\u044b\u043b\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e DHCP \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (\u0432\u0441\u0435 ip \u0431\u044b\u043b\u0438 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c\u0438), \u043a\u0430\u0440\u0442\u044b \u0441\u0435\u0442\u0438, \u0441\u043f\u0438\u0441\u043a\u0430 ip \u0438 mac \u0430\u0434\u0440\u0435\u0441\u043e\u0432. \u042f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043b \u0441\u0435\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0441\u043f\u0438\u0441\u043e\u043a mac \u0438 ip, \u0440\u0430\u0441\u043f\u0435\u0447\u0430\u0442\u0430\u043b \u0438 \u043c\u044b \u0441 \u043a\u043e\u043b\u043b\u0435\u0433\u043e\u0439 \u043f\u043e\u0448\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \u0442\u0435\u0445, \u0443 \u043a\u043e\u0433\u043e \u044d\u0442\u0438 mac \u0430\u0434\u0440\u0435\u0441\u0430. \u041f\u043e\u0442\u043e\u043c \u044f \u0432\u043d\u0435\u0441 \u0432\u0441\u0435 \u044d\u0442\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 excel (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 1). <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"5\" data-colwidth=\"0,140,140,0,0\" width=\"0\">\n<p align=\"center\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041a\u0430\u0431\u0438\u043d\u0435\u0442<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"left\">\u0418\u043c\u044f \u041f\u041a<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"left\">\u0424\u0418\u041e<\/p>\n<\/td>\n<td>\n<p align=\"left\">IP<\/p>\n<\/td>\n<td>\n<p align=\"left\">MAC<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">1<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p>1-1<\/p>\n<\/td>\n<td data-colwidth=\"140\" width=\"140\">\n<p align=\"left\">\u0418\u0432\u0430\u043d\u043e\u0432 <br \/>\u0418\u0432\u0430\u043d<br \/>\u0418\u0432\u0430\u043d\u043e\u0432\u0438\u0447<\/p>\n<\/td>\n<td>\n<p align=\"left\">192.168.0.10<\/p>\n<\/td>\n<td>\n<p align=\"left\">00:00:00:00:00:00<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u041f\u043e\u043b\u0433\u043e\u0434\u0430 \u0441\u043f\u0443\u0441\u0442\u044f \u044f \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0440\u0435\u0448\u0438\u043b \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 DHCP \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0414\u043b\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f ip \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0435 \u0432 config. \u041d\u043e \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e 75 \u0441\u0442\u0440\u043e\u043a \u0441 mac, ip, \u0444\u0430\u043c\u0438\u043b\u0438\u044f\u043c\u0438, \u0431\u044b\u043b\u043e \u043a\u0430\u043a-\u0442\u043e \u043b\u0435\u043d\u044c \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0435 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c python \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0430\u043c \u0432\u0441\u0435 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u0430 dhcp.conf:<\/p>\n<pre><code>host Lastname { hardware ethernet 00:00:00:00:00:00; fixed-address 192.168.0.1; }<\/code><\/pre>\n<ul>\n<li>\n<p><strong>Lastname <\/strong>&#8212; \u0424\u0430\u043c\u0438\u043b\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>hardware ethernet <\/strong>&#8212; MAC \u0430\u0434\u0440\u0435\u0441.<\/p>\n<\/li>\n<li>\n<p><strong>fixed-address<\/strong> &#8212; ip \u0430\u0434\u0440\u0435\u0441 \u0434\u043b\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043a\u0443\u0449\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u043b\u0430 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0424\u0418\u041e \u0432 \u043d\u0435\u0439 \u043f\u043e\u043b\u043d\u043e. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043d\u043e\u0432\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 2) \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u043b \u0444\u0430\u043c\u0438\u043b\u0438\u0438 \u043d\u0430 \u043b\u0430\u0442\u0438\u043d\u0438\u0446\u0443.<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">name<\/p>\n<\/td>\n<td>\n<p align=\"left\">mac<\/p>\n<\/td>\n<td>\n<p align=\"left\">ip<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Ivanov<\/p>\n<\/td>\n<td>\n<p align=\"left\">00:00:00:00:00:00<\/p>\n<\/td>\n<td>\n<p align=\"left\">192.168.0.10<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043b\u0435\u0435 \u044f \u043d\u0430\u0447\u0430\u043b \u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0430 python, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c 3 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430.<\/p>\n<blockquote>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <strong>xlrd<\/strong> \u0438 <strong>pandas<\/strong> 1\u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 excel \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0447\u0438\u0442\u0430\u044f \u0435\u0435 \u043e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432.<\/p>\n<\/blockquote>\n<hr\/>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 1<\/h3>\n<p>\u0425\u043e\u0442\u0435\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 pandas \u043d\u043e \u043e\u043d\u0430 \u043d\u0435 \u0437\u0430\u0432\u0435\u043b\u0430\u0441\u044c \u0438 \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043a\u0438. \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0441\u043a\u043e\u0431\u043a\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c excel. \u0421 \u043f\u0440\u043e\u0442\u044f\u0436\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u044b.<\/p>\n<pre><code>=\"'\"&amp;A1&amp;\"',\" - \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 name =\"'\"&amp;B1&amp;\"',\" - \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 mac =\"'\"&amp;C1&amp;\"',\" - \u0434\u043b\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u0430 ip<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0442\u0430\u043a (\u0442\u0430\u0431\u043b\u0438\u0446\u0430 3).<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td colspan=\"3\">\n<p align=\"center\">\u0422\u0430\u0431\u043b\u0438\u0446\u0430 3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">name<\/p>\n<\/td>\n<td>\n<p align=\"left\">mac<\/p>\n<\/td>\n<td>\n<p align=\"left\">ip<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">&#8216;Ivanov&#8217;<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8217;00:00:00:00:00:00&#8242;,<\/p>\n<\/td>\n<td>\n<p align=\"left\">&#8216;192.168.0.10&#8217;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u043d\u0435\u0441 \u044d\u0442\u043e \u0432\u0441\u0435 \u0432 \u0441\u043f\u0438\u0441\u043a\u0438 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u043b\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c.<\/p>\n<pre><code class=\"python\">mac=['00:00:00:00:00:00', ...] ip=['192.168.0.10', ...] name=['Ivanov', ...]  def write():     with open(\"dhcp.conf\", 'w') as f:         for i,j,k in zip(Config.name, Config.mac, Config.ip):             f.write(f\"host {i}\" + \" {\\n\\thardware ethernet\" + f\" {j};\" + \"\\n\\tfixed-address \" + f\"{k};\" + \"\\n}\\n\\n\")  if __name__ == '__main__':     write()<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c 3 \u0441\u043f\u0438\u0441\u043a\u0430:<\/p>\n<ul>\n<li>\n<p><strong>mac<\/strong> &#8212; \u0434\u043b\u044f mac \u0430\u0434\u0440\u0435\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>ip<\/strong> -\u0434\u043b\u044f ip \u0430\u0434\u0440\u0435\u0441\u043e\u0432<\/p>\n<\/li>\n<li>\n<p><strong>name<\/strong> &#8212; \u0434\u043b\u044f \u0444\u0430\u043c\u0438\u043b\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">mac=['00:00:00:00:00:00', ...] ip=['192.168.0.10', ...] name=['Ivanov', ...]<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def write():<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b dhcp.conf \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0437\u0430\u043f\u0438\u0441\u0438:<\/p>\n<pre><code class=\"python\">with open(\"dhcp.conf\", 'w') as f:<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0430\u043c. <strong>zip<\/strong> &#8212;  \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0435\u0440\u0451\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u0438 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0438\u0437 \u043d\u0438\u0445 \u0441\u043f\u0438\u0441\u043e\u043a (\u043a\u043e\u0440\u0442\u0435\u0436):<\/p>\n<pre><code class=\"python\">for i,j,k in zip(Config.name, Config.mac, Config.ip):<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\">f.write(f\"host {i}\" + \" {\\n\\thardware ethernet\" + f\" {j};\" + \"\\n\\tfixed-address \" + f\"{k};\" + \"\\n}\\n\\n\")<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     write()<\/code><\/pre>\n<hr\/>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 2<\/h3>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 2 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 xlrd.<\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 xlsx \u0444\u043e\u0440\u043c\u0430\u0442 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0444\u0430\u0439\u043b \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 xls.<\/p>\n<pre><code class=\"python\">import xlrd  def write():     loc = (r\"C:\\path\\to\\file\\filename.xls\")     sheet = xlrd.open_workbook(loc).sheet_by_index(0)     with open(\"dhcp.conf\", 'w') as f:         for i in range(sheet.nrows):             f.write(f\"host {sheet.cell_value(i, 0)}\" + \" {\\n\\thardware ethernet\" + f\" {sheet.cell_value(i,1)};\" + \"\\n\\tfixed-address \" + f\"{sheet.cell_value(i,2)};\" + \"\\n}\\n\\n\")              if __name__ == '__main__':     write()<\/code><\/pre>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">import xlrd<\/code><\/pre>\n<p>\u041e\u0431\u044a\u044f\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def write():<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c excel \u0438 \u043b\u0438\u0441\u0442 \u0441 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c 0:<\/p>\n<pre><code class=\"python\">loc = (r\"C:\\path\\to\\file\\filename.xls\") sheet = xlrd.open_workbook(loc).sheet_by_index(0)<\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">sheet = xlrd.open_workbook(r\"C:\\path\\to\\file\\filename.xls\").sheet_by_index(0)<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<pre><code class=\"python\">with open(\"dhcp.conf\", 'w') as f:<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0441\u0442\u0440\u043e\u043a. \u0413\u0434\u0435 &#8216;<strong>sheet.nrows&#8217;<\/strong> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0440\u043e\u043a:<\/p>\n<pre><code class=\"python\"> for i in range(sheet.nrows):<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0444\u0430\u0439\u043b. <strong>sheet.cell_value(i, 0) <\/strong>&#8212; \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043b\u044f \u0433\u0434\u0435 <strong>i <\/strong>&#8212; \u0441\u0442\u0440\u043e\u043a\u0430, <strong>0<\/strong> &#8212; \u0441\u0442\u043e\u043b\u0431\u0435\u0446:<\/p>\n<pre><code class=\"python\">f.write(f\"host {sheet.cell_value(i, 0)}\" + \" {\\n\\thardware ethernet\" + f\" {sheet.cell_value(i,1)};\" + \"\\n\\tfixed-address \" + f\"{sheet.cell_value(i,2)};\" + \"\\n}\\n\\<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     write()<\/code><\/pre>\n<hr\/>\n<h3>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 3<\/h3>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 2 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 pandas.<\/p>\n<pre><code class=\"python\">import pandas as pd  def write():     excel = pd.read_excel(r'C:\\path\\to\\file\\filename.xlsx')     with open(\"dhcp.conf\", 'w') as f:         for i, j, k in zip(excel[\"Name\"].tolist(), excel[\"MAC\"].tolist(), excel[\"IP\"].tolist()):              f.write(f\"host {i}\" + \" {\\n\\thardware ethernet\" + f\" {j};\" + \"\\n\\tfixed-address \" + f\"{k};\" + \"\\n}\\n\\n\")      if __name__ == '__main__':     write()<\/code><\/pre>\n<p>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. <strong>as<\/strong> &#8212; \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u0430:<\/p>\n<pre><code class=\"python\">import pandas as pd<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">def write():<\/code><\/pre>\n<p>\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 excel:<\/p>\n<pre><code class=\"python\">excel = pd.read_excel(r'C:\\path\\to\\file\\filename.xlsx')<\/code><\/pre>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">with open(\"dhcp.conf\", 'w') as f:<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u043c\u0441\u044f \u0446\u0438\u043a\u043b\u043e\u043c \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0430\u043c:<\/p>\n<pre><code class=\"python\">for i, j, k in zip(excel[\"Name\"].tolist(), excel[\"MAC\"].tolist(), excel[\"IP\"].tolist()):<\/code><\/pre>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 &#8216;Name&#8217;, &#8216;mac&#8217;, &#8216;ip&#8217;. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0437 \u043d\u0438\u0445 \u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<pre><code class=\"python\">excel[\"Name\"].tolist(), excel[\"MAC\"].tolist(), excel[\"IP\"].tolist<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a pandas \u0432\u0438\u0434\u0438\u0442 \u043e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435 excel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430:<\/p>\n<pre><code class=\"python\">print (excel.columns.ravel())<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\">f.write(f\"host {i}\" + \" {\\n\\thardware ethernet\" + f\" {j};\" + \"\\n\\tfixed-address \" + f\"{k};\" + \"\\n}\\n\\n<\/code><\/pre>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     write()<\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434 \u0432\u0441\u0435\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0432 \u0432 dhcp.conf:<\/p>\n<pre><code>host Ivanov { hardware ethernet 00:00:00:00:00:00; fixed-address 192.168.0.10; }<\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e.<\/p>\n<p>PS: \u044d\u0442\u043e \u043c\u043e\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/682558\/\"> https:\/\/habr.com\/ru\/post\/682558\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-337068","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337068"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337068\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}