Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- COUNT=0
- LOC=0
- while [[ $COUNT -lt 3 ]]
- do
- RESULT=`dd if=/dev/mtd0ro skip=${i} bs=1 count=8 2>/dev/null`
- if [[ "${RESULT}" == 'macaddr=' ]]
- then
- [[ ${COUNT} -eq 0 ]] & MACLOCATION_0=$(( $LOC + 8 ))
- MAC=`dd if=/dev/mtd0ro skip=${MACLOCATION_0} bs=1 count=17 2>/dev/null`
- echo "MAC=[${MAC}]"
- echo "FOUND [${COUNT}] at address [${LOC}] [${MACLOCATION_0}]"
- COUNT=$(( $COUNT + 1 ))
- [[ $COUNT -eq 3 ]] && break
- fi
- LOC=$(( $LOC + 1 ))
- done; echo $COUNT
- MAC=[38:2C:4A:E3:84:A8]
- FOUND [0] at address [1256] [1264]
- MAC=[38:2C:4A:E3:84:A8]
- FOUND [1] at address [1644] [1652]
- MAC=[38:2C:4A:E3:84:AC]
- FOUND [2] at address [2696] [2704]
- strings -o /dev/mtd0ro | grep add
- admin@RT-AC68P-4131SP:/tmp# strings -o /dev/mtd0ro | grep macaddr
- 2345 et0macaddr=38:2C:4A:E3:84:A8
- 3152 0:macaddr=38:2C:4A:E3:84:A8
- 5206 1:macaddr=38:2C:4A:E3:84:AC
- admin@RT-AC68P-4131SP:/tmp#
- strings -o /dev/mtd0ro | grep macaddr
- for LOCATION in 1 2 3
- do
- # find the offset of the beginning of the line containing "macaddr"
- RAWOFFSETOCT=$(( `strings -o /dev/mtd0ro | grep macaddr | head -n${LOCATION} | tail -n1 | awk '{print $1}'`))
- # convert the offset to decimal
- RAWOFFSETDEC=`printf "%d" \0${RAWOFFSETOCT}`
- # get the string
- RAWMAC=`strings -o /dev/mtd0ro | grep macaddr | head -n${LOCATION} | tail -n1 | awk '{print $2}'`
- # find how many characters there are leading up to the mac itself
- RAWSKIP=$(( ${#RAWMAC} - 17 ))
- # Add the number of leading characters to the offset for the MAC offset
- MACOFFSET=$(( $RAWOFFSETDEC + $RAWSKIP ))
- # Debug
- echo "RAWOFFSETDEC=[${RAWOFFSETDEC}] RAWMAC=[${RAWMAC}] RAWSKIP=[${RAWSKIP}] MACOFFSET=[${MACOFFSET}]"
- #echo "MACOFFSET=[${MACOFFSET}]"
- # Print the MAC
- MAC=`dd if=/dev/mtd0ro skip=${MACOFFSET} bs=1 count=17 2>/dev/null`
- echo "MAC=[${MAC}]"
- done
Advertisement
Add Comment
Please, Sign In to add comment