From: LC's No-Spam Newsreading account on 3 Mar 2010 05:17 On Tue, 2 Mar 2010, pk wrote: > Usually it's a matter of enabling SNMP on the switch (usually it's enabled, It's present but not configured. We (neither me nor the institute net administrator) never bothered to learn that > these days). In that case, based on what you said, I'd go with telnet first, > since it's easily scriptable, and keep http as a last resort. Hmmm ... telnet is scriptable at the price of using expect (which I had to use only twice in my life, one being the other swith case). In the case of the new switches I can't find the relevant info in the telnet interface. Also the script is last resort, I am phasing out the scripts for interactive use (I'd probably keep them for crontabs) in favour of java, and prefer to do HMTL parsing in java > However, consider that the html you get from the device [...] > or it may contain javascript, or.... Yeah, I'm afraid my trouble could be due to imbedded javascript. If I cannot overcome it, I'll explore snmp (in the worst case for java I'll hook it to an external script, as I already do for arping) -- ---------------------------------------------------------------------- nospam(a)mi.iasf.cnr.it is a newsreading account used by more persons to avoid unwanted spam. Any mail returning to this address will be rejected. Users can disclose their e-mail address in the article if they wish so.
From: pk on 3 Mar 2010 06:00 LC's No-Spam Newsreading account wrote: > crontabs) in favour of java, and prefer to do HMTL parsing in java That makes it slightly better, as using a parser is (or should be) a more robust option for parsing html. >> However, consider that the html you get from the device [...] >> or it may contain javascript, or.... > > Yeah, I'm afraid my trouble could be due to imbedded javascript. I was speaking out of personal experience. I once had a device (years ago) that used a peculiar authentication mechanism. Essentially, the authentication page contained a nonce buried into some javascript code. The javascript code, in turn, was associated to the "submit credentials" button. The user entered username and password, and upon submission the javascript code would somehow encrypt the username+password pair (or just the password, I don't remember now) using the nonce, and the result was POSTed to the device. So the POSTed data was different every time. They had been using a script for a long time to automate logins to the device and get to a diagnostic page. This script was using a complicated patchwork of commands, using wget to download the authentication page, sed or grep (or possibly both) to extract the nonce from the javascript, some Perl to replicate the encryption algorithm (that somebody had translated to Perl after reading the javascript code) and compute the data to POST, and finally wget again to send the actual authentication data and to request the diagnostic page. Then again Perl to parse the HTML and extract the actual information the script was supposed to gather. If I'm not mistaken, the device was also setting a cookie at some point, which of course the script had to manage. I don't remember the details, but the script, even if it mostly worked, was quite long, clunky and required some time just to understand what it was doing. With SNMP, that was replaced by a 10-lines script using snmpwalk and snmpget to get the same information and Perl to parse it. And that was due to my lazyness, as doing it all in Perl only, using a SNMP module, would probably have been even shorter. > If I cannot overcome it, I'll explore snmp (in the worst case for java > I'll hook it to an external script, as I already do for arping) See if the above helps. Look at the authentication form HTML source, and see if there's something weird in there. Sniff the data that goes to/from the switch, and see if there's something that you missed or did not foresee in your script. (I still maintain that SNMP is cleaner and easier, but I see your point about having to move to something new)
From: mop2 on 3 Mar 2010 13:29 On Wed, 03 Mar 2010 07:17:18 -0300, LC's No-Spam Newsreading account <nospam(a)mi.iasf.cnr.it> wrote: > Hmmm ... telnet is scriptable at the price of using expect > (which I > had to use only twice in my life, one being the other swith > case). In > the case of the new switches I can't find the relevant info in > the > telnet interface. Also the script is last resort, I am phasing > out > the scripts for interactive use (I'd probably keep them for > crontabs) in favour of java, and prefer to do HMTL parsing in > java > You can try html with shell: x=0;while read -d\>;do printf "<$x>${REPLY%<*}";x=$[x+1];done My option for telnet in the past without expect, bash only: #!/bin/bash exec 2>>/tmp/autoIP.log user='' # user's login name (modem) pass='xxx123yyy' # user's password (modem) ppp=Tel # ppp connection name (modem Alcatel Speed Touch Pro) #Log=/tmp/autoIP.log d="" ### Debug authentication? "1" = yes "" = no exec 3<>/dev/tcp/10.0.0.138/23 Auth(){ read -d$1 -r L<&3;[ $d ]&&echo -n "$L : ">&2; echo -ne "$2\r" >&3;} Send(){ x=0 while true;do b=${1:$x:1}; [ "$b" ]||break echo -n "$b" >&3; read -d"$b" r<&3; x=$[x+1] done echo -ne "\r" >&3; read -d"$2" r <&3; [ "$3" ]&&echo "$r" } getIP(){ Read='' while read N; do [ "$Read" ]&&N=${N#*:}&&echo -n ${N%% *}&&break [ "${N:6:16}" == "$1" ]&&Read=1 done } Auth ":" "$user"; Auth ":" "$pass" read -t 1 -d\> -r L<&3;[ $d ]&&echo -n "$L>">&2 st=0;ppp="$ppp "; ppp=${ppp:0:16} case $1 in IP)Send "ip aplist" ">" o|getIP "$ppp" ;;nat) Send "$1 $2" "=" Send "tcp" "=" Send "$3" "=" Send "$4" "=" Send "$5" "=" Send "$6" "=" o|\ while read L;do [ "${L:1:6}" == "Failed" ]&&st=1;done #[ "$2" == "delete" ]&&Send "dns delete index=0" [ "$2" == "create" ]&&{ #Send "dns add hostname=$7 addr=$5" ">" # endereço externo #Send "dns add hostname=$7 addr=$3" ">" # endereço interno #Send "dns domain domain=$8" ">" #======= # NO ANTIGO autoIP: # [ "$IPa" ] && /sh/telnetAlcatel nat delete 10.0.0.2 1080 $IPa 80 # /sh/telnetAlcatel nat create 10.0.0.2 1080 $IP 80 $Srv $Dom ||\ # com template 0.0.0.0 nao é necessario, o proprio modem cuida disso # /sh/telnetAlcatel nat create 10.0.0.2 1080 0 80 $Srv $Dom ||\ # echo "Houve erro na montagem da tabela NAT no modem" >&2 #======== echo -ne "\n`date +%y%m%d%H%M%S` telnetAlcatel:\n" >&2 Send "nat list" ">" o |grep $3|grep t|\ /usr/bin/tr -d [:cntrl:]|/usr/bin/tr -s " " >&2 echo >&2 } esac exec 3<&- # close connection exit $st
From: Janis Papanagnou on 3 Mar 2010 17:46 mop2 wrote: > On Wed, 03 Mar 2010 07:17:18 -0300, LC's No-Spam Newsreading account > <nospam(a)mi.iasf.cnr.it> wrote: >> Hmmm ... telnet is scriptable at the price of using expect (which I >> had to use only twice in my life, one being the other swith case). In >> the case of the new switches I can't find the relevant info in the >> telnet interface. Also the script is last resort, I am phasing out >> the scripts for interactive use (I'd probably keep them for >> crontabs) in favour of java, and prefer to do HMTL parsing in java >> > > > You can try html with shell: ITYM "bash shell". > x=0;while read -d\>;do printf "<$x>${REPLY%<*}";x=$[x+1];done > > > [...]
From: mop2 on 3 Mar 2010 21:31 On Wed, 03 Mar 2010 19:46:56 -0300, Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote: > mop2 wrote: >> On Wed, 03 Mar 2010 07:17:18 -0300, LC's No-Spam Newsreading >> account <nospam(a)mi.iasf.cnr.it> wrote: >>> Hmmm ... telnet is scriptable at the price of using expect >>> (which I >>> had to use only twice in my life, one being the other swith >>> case). In >>> the case of the new switches I can't find the relevant info >>> in the >>> telnet interface. Also the script is last resort, I am >>> phasing out >>> the scripts for interactive use (I'd probably keep them for >>> crontabs) in favour of java, and prefer to do HMTL parsing in >>> java >>> >> You can try html with shell: > > ITYM "bash shell". > >> x=0;while read -d\>;do printf "<$x>${REPLY%<*}";x=$[x+1];done >> [...] Why? Well, about the syntax, possibly, but the principle is probably viable for some others: $ ksh -c ' > x=0lynx -source http://groups.google.com/not | > while read -d\>;do printf "<$x>${REPLY%<*}";x=$((x+1));done' <0> <1><2> <3> <4>404 Not Found<5> <6><7><8> <9><10> <11> <12> <13> <14><15><16> <17><18>G<19><20>o<21><22>o<23><24>g<25><26>l<27><28>e<29> <30> <31> <32><33> <34><35><36><37>Error<38><39><40> <41><42> <43><44><45> <46> <47>Not Found<48> The requested URL <49>/not<50>was not found on this server. <51> <52> <53><54><55><56><57><58><59> <60>$
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Processing stdin in blocks Next: Bash directory traversal with spaces |