{"id":287377,"date":"2018-08-16T14:07:58","date_gmt":"2018-08-16T10:07:58","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=287377"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=287377","title":{"rendered":"\u041f\u043e\u0438\u0441\u043a \u043f\u043e MAC-\u0430\u0434\u0440\u0435\u0441\u0443 \u043d\u0430 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430\u0445 Juniper"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/company\/plarium\/blog\/420013\/\" class=\"post__text post__text-html js-mediator-article\">\u0412 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0447\u0430\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u043d\u0430 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u0442\u0443 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 MAC-\u0430\u0434\u0440\u0435\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043b\u0435\u0433\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432 \u0441\u0435\u0442\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u043e\u0432, \u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 30, \u0432\u0441\u0451 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f. \u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u043d\u0430 Python, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0449\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 MAC-\u0430\u0434\u0440\u0435\u0441 \u0432 \u0441\u0435\u0442\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043c\u044f \u0438 \u043f\u043e\u0440\u0442 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u044d\u0442\u043e\u0442 MAC.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ui\/sl\/tm\/uisltmawb4week0qnbf04l0p7um.png\"><\/p>\n<p>  \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0415\u0441\u043b\u0438 \u0434\u0438\u0437\u0430\u0439\u043d \u0441\u0435\u0442\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440 <b>CORE<\/b>, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u044b \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f <b>DS<\/b> (Distribution Switch), \u0430 \u043a \u043d\u0438\u043c, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u044b \u0443\u0440\u043e\u0432\u043d\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 <b>AS<\/b> (Access Switch). \u042d\u0442\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u0412 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0430 \u043f\u043e\u0440\u0442\u0443 \u0432\u044b\u0448\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0441\u0435 MAC-\u0430\u0434\u0440\u0435\u0441\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445 \u043a \u043d\u0438\u0436\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0443. <\/p>\n<p>  \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0435 \u043d\u0430\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043a \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0443 <b>AS3<\/b>, \u0442\u043e, \u043d\u0430\u0447\u0430\u0432 \u043f\u043e\u0438\u0441\u043a \u0441 <b>CORE<\/b>, \u043c\u044b \u043d\u0430\u0439\u0434\u0435\u043c \u044d\u0442\u043e\u0442 \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u043f\u043e\u0440\u0442\u0443, \u0432\u0435\u0434\u0443\u0449\u0435\u043c\u0443 \u043a <b>DS1<\/b>. \u0417\u0430\u0439\u0434\u044f \u043d\u0430 <b>DS1<\/b>, \u043c\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043c \u044d\u0442\u043e\u0442 MAC \u043d\u0430 \u043f\u043e\u0440\u0442\u0443, \u0432\u0435\u0434\u0443\u0449\u0435\u043c\u0443 \u043a <b>AS2<\/b>, \u0437\u0430\u0439\u0434\u044f \u043d\u0430 <b>AS2<\/b>, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043e\u043d \u0432\u0435\u0434\u0435\u0442 \u043d\u0430\u0441 \u043a <b>AS3<\/b>, \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 <b>AS3<\/b> \u043c\u044b \u043d\u0430\u0439\u0434\u0435\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043f\u043e\u0440\u0442, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0435 \u043d\u0430\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e.<\/p>\n<p>  \u0414\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u0441\u0451 \u0440\u0443\u043a\u0430\u043c\u0438 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u044b \u0432 \u0446\u0438\u043a\u043b\u0435 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c, \u0433\u0434\u0435 \u0430\u043f\u043b\u0438\u043d\u043a, \u0430 \u0433\u0434\u0435 \u043d\u0435\u0442 \u0442\u043e\u0436\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438 \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f.<\/p>\n<h4>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438.<\/h4>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 MAC <b>08:62:66:c7:b3:45<\/b> \u043d\u0430 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0435 Juniper, \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code>show ethernet-switching table | match 08:62:66:c7:b3:45<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 MAC \u0435\u0441\u0442\u044c, \u043e\u0442\u0432\u0435\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:<\/p>\n<pre><code>vlan151  08:62:66:c7:b3:45   D  -   xe-0\/0\/23.0<\/code><\/pre>\n<p>  \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d MAC. \u041d\u043e \u043a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0443\u0434\u0430 \u0432\u0435\u0434\u0435\u0442 \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441? \u0418 \u0442\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442<b> Interface Descriptions<\/b>. \u042d\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c.<\/p>\n<p>  \u041a\u043e\u043c\u0430\u043d\u0434\u0430 <\/p>\n<pre><code>show interfaces xe-0\/0\/23 descriptions<\/code><\/pre>\n<p>  \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code>Interface       Admin Link Description xe-0\/0\/23       up    up   SW&gt;DS1<\/code><\/pre>\n<p>  \u041f\u0440\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432\u0435\u0434\u0435\u0442 \u043a \u043d\u0438\u0436\u0435\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0443:<\/p>\n<pre><code>set interfaces xe-0\/0\/23 description SW&gt;DS1<\/code><\/pre>\n<p>  <\/p>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h4>\n<p>  \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<ol>\n<li>\u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043f\u043e SSH \u043d\u0430 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440; <\/li>\n<li>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u043d\u0430 \u043a\u0430\u043a\u043e\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 MAC-\u0430\u0434\u0440\u0435\u0441;<\/li>\n<li>\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c Description \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430;<\/li>\n<li>\u0435\u0441\u043b\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432\u0435\u0434\u0435\u0442 \u043a \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0443, \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0437\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440.<\/li>\n<\/ol>\n<p>  <\/p>\n<pre><code class=\"python\">#\u0432 \u044d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0431\u0443\u0434\u0443\u0442 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043f\u043e\u0438\u0441\u043a\u0430 searchpass = []  #main \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 MAC-\u0430\u0434\u0440\u0435\u0441 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e checkswitch, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0438\u043c\u044f \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430 \u0438 MAC-\u0430\u0434\u0440\u0435\u0441. \u0412\u0435\u0441\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u043e\u0438\u0441\u043a\u0430 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043e\u043a searchpass \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 json.  def main(argv):  \tmac_addr = argv[0]  \tcheckswitch('CORE',mac_addr) \tfor switch in searchpass: \t\tprint (json.dumps(switch, ensure_ascii=False))  if __name__ == \"__main__\":    main(sys.argv[1:])   #\u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 MAC-\u0430\u0434\u0440\u0435\u0441\u0430  def checkswitch(hostname,mac_addr): try: #\u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043b\u044e\u0447\u0443 host \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0438\u043c\u044f \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430 \treturnvalue = {} \treturnvalue['host']=hostname  #sendCommand \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u043a \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0443 \u043f\u043e SSH \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043f\u043e\u0438\u0441\u043a\u0430 MAC-\u0430\u0434\u0440\u0435\u0441\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0446\u0438\u0438 \tanswer = sendCommand(hostname,'show ethernet-switching table | match '+mac_addr) #\u0434\u0435\u043b\u0438\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0430 \u043a\u043e\u043b\u043e\u043d\u043a\u0438, \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u043c\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 #vlan151  08:62:66:c7:b3:45   D  -   xe-0\/0\/23.0 if(answer!=0): \t\tiface = answer.split()[4] \t\treturnvalue['iface']=iface #\u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c description \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u043d\u0443\u0436\u043d\u043e \u043e\u0442\u0440\u0435\u0437\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 2 \u0441\u0438\u043c\u0432\u043e\u043b\u0430 .0 \u043e\u0442 \u0438\u043c\u0435\u043d\u0438 \u0438 \u0437\u0430\u0431\u0440\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0441\u0442\u0440\u043e\u043a\u0443 #xe-0\/0\/23       up    up   SW&gt;DS01 \t\tanswer = sendCommand(hostname,'show interfaces '+iface[:-2]+' descriptions | last 1 | no-more') \t\tiface = answer.split() #\u0415\u0441\u043b\u0438 description \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u0435\u0441\u0442\u044c, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u043d \u0441 SW&gt;. \u0415\u0441\u043b\u0438 \u0434\u0430, \u043e\u0442\u0440\u0435\u0437\u0430\u0435\u043c \u044d\u0442\u0438 3 \u0441\u0438\u043c\u0432\u043e\u043b\u0430, \u0431\u0435\u0440\u0435\u043c \u0438\u043c\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430 \u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441\u043d\u043e\u0432\u0430.  \t\tif(len(iface)&gt;2): \t\t\tiface=iface[3] \t\t\treturnvalue['description']=iface \t\telse: \t\t\treturnvalue['description']='none' \t\tsearchpass.append(returnvalue) \t\tif (iface[:3]=='SW&gt;'): \t\t\tcheckswitch(iface[3:],mac_addr) \telse: \t\treturnvalue['iface']='none' \t\tsearchpass.append(returnvalue)  \texcept Exception as e: \t\tprint(e)<\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u043f\u043e \u0432\u0441\u0435\u043c \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430\u043c \u0441\u0435\u0442\u0438, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u044f\u0434\u0440\u0430, \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 MAC. \u0414\u043b\u044f \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0432 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 descriptions \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u0445, \u0430 \u0442\u043e\u043f\u043e\u043b\u043e\u0433\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u044e\u0431\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430:<\/p>\n<pre><code>python findmac.py 00:17:fc:21:e8:f9  {\"host\": \"CORE\", \"iface\": \"xe-0\/0\/23.0\", \"description\": \"SW&gt;DS1\"} {\"host\": \"DS1\", \"iface\": \"xe-0\/0\/11.0\", \"description\": \"SW&gt;AS2\"} {\"host\": \"AS2\", \"iface\": \"xe-1\/0\/1.0\", \"description\": \"SW&gt;AS3\"} {\"host\": \"AS3\", \"iface\": \"ge-0\/0\/26.0\", \"description\": \"none\"}<\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 MAC \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442, \u043f\u043e\u043b\u0443\u0447\u0438\u043c<\/p>\n<pre><code>{\"host\": \"CORE\", \"iface\": \"none\"}<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u2013 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0439 \u043d\u0430\u0441 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440 \u0438 \u043f\u043e\u0440\u0442, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0432\u0435\u0441\u044c \u043f\u0443\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u0430.<\/p>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u2013 \u043f\u043e\u0434 \u0441\u043f\u043e\u0439\u043b\u0435\u0440\u043e\u043c, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">findmac.py<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"> import paramiko import time import sys import json import threading import logging   login = 'user1' password = 'pass1234' searchpass = [] port = 22  class LogPipe(threading.Thread): \tdef __init__(self, level): \t\tthreading.Thread.__init__(self) \t\tself.daemon = False \t\tself.level = level \t\tself.fdRead, self.fdWrite = os.pipe() \t\tself.pipeReader = os.fdopen(self.fdRead) \t\tself.start()  \tdef fileno(self): \t\treturn self.fdWrite  \tdef run(self): \t\tfor line in iter(self.pipeReader.readline, ''): \t\t\tlogging.log(self.level, line.strip('\\n')) \t\tself.pipeReader.close()  \tdef close(self): \t\tos.close(self.fdWrite)  def execute_ssh_command(host, port, username, password, command):     try:         # Create the SSH client.         ssh = paramiko.SSHClient()         ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())           # Connect to the host.         ssh.connect(host, port, username, password, look_for_keys=False)           # Send the command (non-blocking)         stdin, stdout, stderr = ssh.exec_command(command)           # Wait for the command to terminate         while not stdout.channel.exit_status_ready() and not stdout.channel.recv_ready():             time.sleep(1)           stdoutstring = stdout.readlines()         stderrstring = stderr.readlines()         return stdoutstring, stderrstring     finally:         if ssh is not None:             # Close client connection.             ssh.close()  def sendCommand (hostname,command): \treturnvalue = 0 \tlogging.info('Host '+hostname+', command: '+command) \tTry: #add .mydomain for FQDN \t\t(stdoutstring, stderrstring) = execute_ssh_command(hostname+'.mydomain', port, login, password, command+'\\n') \t\tif (len(stdoutstring)&gt;0): \t\t\tlogging.info(stdoutstring[0]) \t\tif (len(stderrstring)&gt;0): \t\t\tlogging.info(stderrstring[0]) \texcept Exception as e: \t\treturn returnvalue \telse: \t\treturnvalue = stdoutstring[0] \tfinally: \t\treturn returnvalue \t\t\t \t\t\t def checkswitch(hostname,mac_addr): \ttry: \t\treturnvalue = {} \t\treturnvalue['host']=hostname \t\tanswer = sendCommand(hostname,'show ethernet-switching table | match '+mac_addr) \t\tif(answer!=0): \t\t\tiface = answer.split()[4] \t\t\treturnvalue['iface']=iface \t\t\t#cut .0 prefix in the interface name \t\t\tanswer = sendCommand(hostname,'show interfaces '+iface[:-2]+' descriptions | last 1 | no-more') \t\t\tiface = answer.split() \t\t\tif(len(iface)&gt;2): \t\t\t\tiface=iface[3] \t\t\t\treturnvalue['description']=iface \t\t\telse: \t\t\t\treturnvalue['description']='none' \t\t\tsearchpass.append(returnvalue) \t\t\tif (iface[:3]=='SW&gt;'): \t\t\t\tcheckswitch(iface[3:],mac_addr) \t\telse: \t\t\treturnvalue['iface']='none' \t\t\tsearchpass.append(returnvalue) \texcept Exception as e: \t\tlogging.info(e)  \t\t\t def main(argv):  \tmac_addr = argv[0] \t \t#configure log \tlogging.basicConfig(filename='\/var\/log\/findmac.log', level=logging.INFO, format='%(asctime)s %(message)s') \tlogging.info('Find MAC: '+mac_addr) \tcheckswitch('CORE',mac_addr) \tfor switch in searchpass: \t\tprint (json.dumps(switch, ensure_ascii=False))  if __name__ == \"__main__\": \tmain(sys.argv[1:])<\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <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\/company\/plarium\/blog\/420013\/\"> https:\/\/habr.com\/company\/plarium\/blog\/420013\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/company\/plarium\/blog\/420013\/\" class=\"post__text post__text-html js-mediator-article\">\u0412 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0447\u0430\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c, \u043d\u0430 \u043a\u0430\u043a\u043e\u043c \u043f\u043e\u0440\u0442\u0443 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 MAC-\u0430\u0434\u0440\u0435\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u0417\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043b\u0435\u0433\u043a\u043e, \u0435\u0441\u043b\u0438 \u0432 \u0441\u0435\u0442\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u043e\u0432, \u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 30, \u0432\u0441\u0451 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f. \u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c \u043d\u0430 Python, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0449\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 MAC-\u0430\u0434\u0440\u0435\u0441 \u0432 \u0441\u0435\u0442\u0438 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043c\u044f \u0438 \u043f\u043e\u0440\u0442 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u044d\u0442\u043e\u0442 MAC.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ui\/sl\/tm\/uisltmawb4week0qnbf04l0p7um.png\"><\/p>\n<p>  \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.  <\/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-287377","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287377","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=287377"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287377\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}