{"id":1079,"date":"2014-07-07T20:41:39","date_gmt":"2014-07-07T20:41:39","guid":{"rendered":"http:\/\/kraftek.com\/blog\/?p=1079"},"modified":"2014-07-07T20:41:39","modified_gmt":"2014-07-07T20:41:39","slug":"get-vlan-using-snoop","status":"publish","type":"post","link":"\/blog\/index.php\/get-vlan-using-snoop\/","title":{"rendered":"Get vlan using snoop"},"content":{"rendered":"<p>You could use this script snoopdcp.sh, usage is like this:<\/p>\n<pre>\r\n# .\/snoopdcp.sh nxge1\r\n<\/pre>\n<p>The script goes like this:<\/p>\n<pre>\r\n#!\/bin\/bash\r\n\r\nInterface=$1\r\n\r\nif [[ -z \"$Interface\" ]]\r\nthen\r\n  echo \"[FATAL]Usage $0 <interface>\"\r\n  exit 1\r\nfi\r\n\r\n\r\n#snoopfile=$(mktemp \/tmp\/snoopy.XXXX)\r\nsnoopfile=\/tmp\/snoopy.XXXX.$$\r\nsnoop -d $Interface -c 1 -vv  -o $snoopfile 'dst 01:00:0c:cc:cc:cc and length > 50'\r\ninstr=$(snoop -i $snoopfile  -x 26 | nawk -F: ' { print $2 } ' |  cut -b1-41|  sed -e 's\/ \/\/g' | nawk 'BEGIN {ORS=\"\"} {print toupper($1)}')\r\nrm -f -- $snoopfile\r\n\r\nwhile  [[ -n \"$instr\" ]]\r\ndo\r\n  typ=`echo $instr | cut -b1-4`\r\n  lhex=`echo $instr | cut -b5-8`\r\n  length=$(echo \"ibase=16; $lhex*2\" | bc)\r\n  next=$(echo \"ibase=16; $lhex*2+1\" | bc)\r\n  if [ $length -gt 8 ]\r\n  then\r\n    texthex=`echo $instr | cut -b9-$length`\r\n  else\r\n    texthex=\"\"\r\n  fi\r\n  #  echo \"$typ $lhex $texthex\"\r\n  if [ $typ == \"0001\" ]\r\n  then\r\n    printf \"Switchname: \"\r\n    while  [ $texthex ]\r\n    do\r\n      charhex=`echo $texthex | cut -b1-2`\r\n      chardec=$(echo \"ibase=16; $charhex\" | bc)\r\n      printf \"%b\" `printf '\\x%x' $chardec 2>\/dev\/null`\r\n      texthex=`echo $texthex | cut -b3-`\r\n    done\r\n    echo \" \"\r\n  fi\r\n  if [ $typ == \"0003\" ]\r\n  then\r\n    printf \"Switchport: \"\r\n    while  [ $texthex ]\r\n    do\r\n      charhex=`echo $texthex | cut -b1-2`\r\n      chardec=$(echo \"ibase=16; $charhex\" | bc)\r\n      printf \"%b\" `printf '\\x%x' $chardec 2>\/dev\/null`\r\n      texthex=`echo $texthex | cut -b3-`\r\n    done\r\n    echo \" \"\r\n  fi\r\n  if [ $typ == \"000A\" ]\r\n  then\r\n    echo \"VLAN: 0x$texthex $(echo \"ibase=16; $texthex\" | bc)\"\r\n  fi\r\n  if [ $typ == \"000B\" ]\r\n  then\r\n    echo \"Duplex: $texthex\"\r\n  fi\r\n  instr=`echo $instr | cut -b$next-`\r\ndone\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You could use this script snoopdcp.sh, usage is like this: # .\/snoopdcp.sh nxge1 The script goes like this: #!\/bin\/bash Interface=$1 if [[ -z &#8220;$Interface&#8221; ]] then echo &#8220;[FATAL]Usage $0 &#8221; exit 1 fi #snoopfile=$(mktemp \/tmp\/snoopy.XXXX) snoopfile=\/tmp\/snoopy.XXXX.$$ snoop -d $Interface -c 1 -vv -o $snoopfile &#8216;dst 01:00:0c:cc:cc:cc and length > 50&#8217; instr=$(snoop -i $snoopfile -x 26 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1079","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=1079"}],"version-history":[{"count":1,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1079\/revisions"}],"predecessor-version":[{"id":1080,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/posts\/1079\/revisions\/1080"}],"wp:attachment":[{"href":"\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=1079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=1079"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=1079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}