{"id":366,"date":"2016-11-03T23:30:31","date_gmt":"2016-11-03T23:30:31","guid":{"rendered":"https:\/\/avalon.land\/blog\/?p=366"},"modified":"2017-10-26T10:48:29","modified_gmt":"2017-10-26T10:48:29","slug":"vlan-mac-port-from-switch-fdb","status":"publish","type":"post","link":"https:\/\/avalon.land\/blog\/it\/vlan-mac-port-from-switch-fdb\/","title":{"rendered":"vlan\/mac\/port from switch fdb"},"content":{"rendered":"<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n \r\nHOST=$1\r\nPORTPARAM=$2\r\n \r\nif &#x5B;&#x5B; -n &quot;$PORTPARAM&quot; &amp;&amp; ( &quot;$PORTPARAM&quot; -lt 0 || &quot;$PORTPARAM&quot; -gt 24 ) ]]; then\r\n    echo &quot;Error port number!&quot;\r\n    exit\r\nfi\r\n \r\nfor string in `snmpwalk -v 2c -c public $HOST 1.3.6.1.2.1.17.7.1.2.2.1.2 -O qn|sed -e &quot;s\/^\\.\/\/g&quot; -e &quot;s\/ \/.\/g&quot;`; do\r\n    decmac=$(echo $string|awk -F &quot;.&quot; &#039;{print $15&quot;;&quot;$16&quot;;&quot;$17&quot;;&quot;$18&quot;;&quot;$19&quot;;&quot;$20}&#039;)\r\n    vlan=$(echo $string|awk -F &quot;.&quot; &#039;{print $14 }&#039;)\r\n    mac=&quot;&quot;\r\n    for hex in `echo &quot;obase=16; $decmac&quot;|bc`; do\r\n    if &#x5B; ${#hex} == &quot;1&quot; ]; then\r\n        hex=&quot;0&quot;$hex\r\n    fi\r\n    if &#x5B; -z $mac ]; then\r\n        mac=$hex\r\n    else\r\n        mac=$mac&quot;:&quot;$hex\r\n    fi\r\n    done\r\n    port=$(echo $string|awk -F &quot;.&quot; &#039;{print $21}&#039;)\r\n    if &#x5B; -z &quot;$PORTPARAM&quot; ]; then\r\n    printf $vlan&quot;\\t&quot;$mac&quot;\\t&quot;$port&quot;\\n&quot;\r\n    elif &#x5B; $PORTPARAM == $port ]; then\r\n    printf $vlan&quot;\\t&quot;$mac&quot;\\t&quot;$port&quot;\\n&quot;\r\n    fi\r\ndone\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash HOST=$1 PORTPARAM=$2 if &#x5B;&#x5B; -n &quot;$PORTPARAM&quot; &amp;&amp; ( &quot;$PORTPARAM&quot; -lt 0 || &quot;$PORTPARAM&quot; -gt 24 ) ]]; then echo &quot;Error port number!&quot; exit fi&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/avalon.land\/blog\/it\/vlan-mac-port-from-switch-fdb\/\">Continue reading<span class=\"screen-reader-text\">vlan\/mac\/port from switch fdb<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-366","post","type-post","status-publish","format-standard","hentry","category-it","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/posts\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":2,"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":368,"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/posts\/366\/revisions\/368"}],"wp:attachment":[{"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avalon.land\/blog\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}