Triggertftp
From DD-WRT Wiki
(Difference between revisions)
Revision as of 09:23, 27 February 2009 (edit) Lavalys (Talk | contribs) (Removing all content from page) ← Previous diff |
Current revision (16:53, 30 April 2010) (edit) (undo) Glenn (Talk | contribs) (catspec) |
||
(2 intermediate revisions not shown.) | |||
Line 1: | Line 1: | ||
+ | # small script to help with tftp boot, change out the values of the variable at the top to your values | ||
+ | # the use of an intermediate switch is highly recommended | ||
+ | #IMAGE=f5d7230-4_4.03.03.bin | ||
+ | #IMAGE=dd-wrt.v24-9517_VINT_mini_usb.bin | ||
+ | IMAGE=dd-wrt.v24_generic-8184.bin | ||
+ | #f5d7230-4_4.03.03.bin | ||
+ | # current IP of the router | ||
+ | OLD=192.168.2.1 | ||
+ | # address of the router if it flashes successfully | ||
+ | NEW=192.168.1.1 | ||
+ | # interface on the machine providing the tftp boot and where this script is being run. | ||
+ | INTERFACE=eth0 | ||
+ | set -e | ||
+ | if test -f "$IMAGE" | ||
+ | then | ||
+ | echo $IMAGE exists starting ping loop | ||
+ | else | ||
+ | echo file: $IMAGE doesnot exist >&2 | ||
+ | exit 2 | ||
+ | fi | ||
+ | CURRENT_IP=`ip addr show "$INTERFACE"| awk '$1 == "inet" { print $2}'` | ||
+ | if test -z "$CURRENT_IP" | ||
+ | then | ||
+ | echo "Interface address for $INTERFACE not found." >&2 | ||
+ | exit 2 | ||
+ | fi | ||
+ | count=0 | ||
+ | until ping -c 2 -i .2 -n -w 60 $OLD || test $count -gt 5 | ||
+ | do | ||
+ | count=$(( $count + 1)) | ||
+ | done | ||
+ | atftp --option "mode octet" --option "timeout 60" --verbose --trace -p -l "$IMAGE" "$OLD" | ||
+ | # waiting longer than needed x2 | ||
+ | sleep 120 | ||
+ | ping -c 1 $OLD | ||
+ | if test $? -eq 0 | ||
+ | then | ||
+ | echo old address is still responding, probably tftp boot failed >&2 | ||
+ | exit 3 | ||
+ | else | ||
+ | # hardcoded | ||
+ | # using class c addressing | ||
+ | ip addr del $CURRENT_IP dev $INTERFACE | ||
+ | ip addr add ${NEW}/24 dev $INTERFACE | ||
+ | ping -c 4 $NEW | ||
+ | nmap $NEW | ||
+ | fi | ||
+ | [[Category:Flashing networking hardware]] |
Current revision
# small script to help with tftp boot, change out the values of the variable at the top to your values # the use of an intermediate switch is highly recommended #IMAGE=f5d7230-4_4.03.03.bin #IMAGE=dd-wrt.v24-9517_VINT_mini_usb.bin IMAGE=dd-wrt.v24_generic-8184.bin #f5d7230-4_4.03.03.bin # current IP of the router OLD=192.168.2.1 # address of the router if it flashes successfully NEW=192.168.1.1 # interface on the machine providing the tftp boot and where this script is being run. INTERFACE=eth0 set -e if test -f "$IMAGE" then echo $IMAGE exists starting ping loop else echo file: $IMAGE doesnot exist >&2 exit 2 fi CURRENT_IP=`ip addr show "$INTERFACE"| awk '$1 == "inet" { print $2}'` if test -z "$CURRENT_IP" then echo "Interface address for $INTERFACE not found." >&2 exit 2 fi count=0 until ping -c 2 -i .2 -n -w 60 $OLD || test $count -gt 5 do count=$(( $count + 1)) done atftp --option "mode octet" --option "timeout 60" --verbose --trace -p -l "$IMAGE" "$OLD" # waiting longer than needed x2 sleep 120 ping -c 1 $OLD if test $? -eq 0 then echo old address is still responding, probably tftp boot failed >&2 exit 3 else # hardcoded # using class c addressing ip addr del $CURRENT_IP dev $INTERFACE ip addr add ${NEW}/24 dev $INTERFACE ping -c 4 $NEW nmap $NEW fi