06-06-2007 04:25 PM
I'm trying to have my router use Tcl to pull down a webpage from a cable modem.
Here's my code so far.
set sock [socket 192.168.100.1 80]
puts $sock "GET /signaldata.htm HTTP/1.0\n\n"
flush $sock
set result [ gets $sock ]
puts stdout "OUTPUT:\n$result"
set exit_msg "closing socket"
close $sock
It doesn't work. All I get is:
OUTPUT:
I know the URL works because I can pull it up fine from my browser and a telnet to port 80 from the router itself also opens the socket for a brief moment.
Can anyone tell me what I'm doing wrong?
Thanks
06-12-2007 04:55 AM
See my earlier snmp-context.tcl on how to use catch effectively. The catch proc allows you to intercept an error before it terminates your script's execution.
To extract a certain element from a string, you will need to use regular expressions. There are examples in my snmp-context.tcl script as well as in my other post to you on your other TCL scripting thread.
06-12-2007 05:05 PM
I thought regular expressions would be the answer, however, I am not sure how to put the output of a show command into a variable. I am having trouble using your script as an example because it is very in depth. I looked at all cases where you have used "regex" but none of it really makes sense to me.
In regards to my other TCL script, I cannot find the URL, are you able to paste it so I can look at it? (I am somewhat new to these forums).
Thanks a lot for your help.
06-12-2007 05:06 PM
The testprog.tcl script I redid for you includes three very simple examples of storing the output of a show command into a variable. The previous Forum thread to which I referred is http://forum.cisco.com/eforum/servlet/NetProf?page=netprof&forum=Network%20Infrastructure&topic=Network%20Management&CommCmd=MB%3Fcmd%3Ddisplay_location%26location%3D.1ddebbe1 . I included a simple regexp example based on your initial script.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide