CloneNum3

openwrt find mac location

Sep 3rd, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.87 KB | None | 0 0
  1. COUNT=0
  2. LOC=0
  3. while [[ $COUNT -lt 3 ]]
  4. do
  5.   RESULT=`dd if=/dev/mtd0ro skip=${i} bs=1 count=8 2>/dev/null`
  6.   if [[ "${RESULT}" == 'macaddr=' ]]
  7.   then
  8.     [[ ${COUNT} -eq 0 ]] & MACLOCATION_0=$(( $LOC + 8 ))
  9.  
  10.     MAC=`dd if=/dev/mtd0ro skip=${MACLOCATION_0} bs=1 count=17 2>/dev/null`
  11.     echo "MAC=[${MAC}]"
  12.  
  13.     echo "FOUND [${COUNT}] at address [${LOC}] [${MACLOCATION_0}]"
  14.  
  15.     COUNT=$(( $COUNT + 1 ))
  16.     [[ $COUNT -eq 3 ]] && break
  17.   fi
  18.   LOC=$(( $LOC + 1 ))
  19. done; echo $COUNT
  20.  
  21.  
  22.  
  23. MAC=[38:2C:4A:E3:84:A8]
  24. FOUND [0] at address [1256] [1264]
  25. MAC=[38:2C:4A:E3:84:A8]
  26. FOUND [1] at address [1644] [1652]
  27. MAC=[38:2C:4A:E3:84:AC]
  28. FOUND [2] at address [2696] [2704]
  29.  
  30.  
  31. strings -o /dev/mtd0ro | grep add
  32.  
  33. admin@RT-AC68P-4131SP:/tmp# strings -o /dev/mtd0ro | grep macaddr
  34.    2345 et0macaddr=38:2C:4A:E3:84:A8
  35.    3152 0:macaddr=38:2C:4A:E3:84:A8
  36.    5206 1:macaddr=38:2C:4A:E3:84:AC
  37. admin@RT-AC68P-4131SP:/tmp#
  38.  
  39.  
  40.  
  41.  
  42. strings -o /dev/mtd0ro | grep macaddr
  43.  
  44. for LOCATION in 1 2 3
  45. do
  46.  
  47.   # find the offset of the beginning of the line containing "macaddr"
  48.   RAWOFFSETOCT=$(( `strings -o /dev/mtd0ro | grep macaddr | head -n${LOCATION} | tail -n1 | awk '{print $1}'`))
  49.  
  50.   # convert the offset to decimal
  51.   RAWOFFSETDEC=`printf "%d" \0${RAWOFFSETOCT}`
  52.  
  53.   # get the string
  54.   RAWMAC=`strings -o /dev/mtd0ro | grep macaddr | head -n${LOCATION} | tail -n1 | awk '{print $2}'`
  55.  
  56.   # find how many characters there are leading up to the mac itself
  57.   RAWSKIP=$(( ${#RAWMAC} - 17 ))
  58.  
  59.   # Add the number of leading characters to the offset for the MAC offset
  60.   MACOFFSET=$(( $RAWOFFSETDEC + $RAWSKIP ))
  61.  
  62.   # Debug
  63.   echo "RAWOFFSETDEC=[${RAWOFFSETDEC}] RAWMAC=[${RAWMAC}] RAWSKIP=[${RAWSKIP}] MACOFFSET=[${MACOFFSET}]"
  64.   #echo "MACOFFSET=[${MACOFFSET}]"
  65.  
  66.   # Print the MAC
  67.   MAC=`dd if=/dev/mtd0ro skip=${MACOFFSET} bs=1 count=17 2>/dev/null`
  68.   echo "MAC=[${MAC}]"
  69.  
  70. done
Advertisement
Add Comment
Please, Sign In to add comment