#!/usr/local/bin/perl # upload firmware into AFAR radios over a telnet connection # # syntax: # perl afarload.pl ipaddress firmwarefile [password] # # (firmwarefile needs to be in the local directory with # .dwn file name extension) $PW = "public"; # telnet password $ePW = "pw2"; # enable password $radio = $ARGV[0]; $fname = $ARGV[1]; if ($#ARGV > 1) { $PW = $ARGV[2]; } if ($#ARGV > 2) { $ePW = $ARGV[3]; } open(I,"$fname.dwn") || die; $port = "23"; $pf_inet = 2; $sock_stream = 1; $tcp_proto = 6; $enabled = 0; $lines = 0; $sockaddr = 'S n a4 x8'; ($name, $aliases, $type, $len, $thataddr) = gethostbyname($radio); $that = pack($sockaddr, 2, $port, $thataddr); socket(S, $pf_inet, $sock_stream, $tcp_proto) || die "socket: $!"; # chop($hostname = `hostname`); # ($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname); # $this = pack($sockaddr, 2, 0, $thisaddr); # bind(S, $this) || die "bind: $!"; connect(S, $that) || die "connect"; select(S); $| = 1; select(stdout); $| = 1; while (1) { if(getc(S) eq ':') { last; } } printf"Sending password\n"; printf S "$PW\n"; while (1) { $c = getc(S); if ($c eq '#') { $enabled = 1; } if ($c eq '>') { last; } } if ($enabled == 0) { printf"Sending e-password\n"; printf S "u en=$ePW\n"; while(1) { if (getc(S) eq '>') { last; } } } printf"Sending download command\n"; printf S "download-file destination=$fname method=inline\n"; $L=; printf"$L\n"; while(){ $lines++; print S "$_"; } printf S "\n\nexit\n"; printf "Sent %d lines\n", $lines; sleep(2); close(S); # End