Jump to content


Photo

Tcl Scripting Help


  • Please log in to reply
1 reply to this topic

#1 Tyler

Tyler
  • Members
  • 415 posts

Posted 11 June 2014 - 02:35 AM

I'm looking for some assistance with this TCL script. I'm working on developing a very basic script that will ask the user how many IP's they want to enter, then collect each of those IP's into a list so that they can be ping'd. I'm brand new to TCL scripting as of last week and I'm having two issues with the following script (I apologize ahead of time, as this script is probably pretty sloppy): 
 

 

lappend iplist 
set y 0 

puts "This script will ping each address that you specify." 
puts -nonewline "How many IP’s will you enter? : " 
flush stdout 
gets stdin numberof 

puts "" 

for {set x 0} {$x<$numberof} {incr x} { 
incr y 
puts -nonewline "IP Address " 
puts -nonewline $y 
puts -nonewline " : " 
flush stdout 
lappend iplist [gets stdin ?address?] 
} 


foreach item $iplist { 
{ping $item 
} 
} 
 

 

 

The first issue is that my list is not being created the right way. The output will work correctly, but in testing I tried using just whole numbers to make sure the list was working. So, I entered "2" addresses. The loop works fine. However, entering IP addresses of 5 and 10, I noticed the list creates 1 and 2. Basically, the list appends to the end however many digits are in the stdin ?address?. This doesn't make any sense to me whatsoever. 


The second issue is the last 'for' loop. I'm not sure how to actually ping each item in the list, as I get "invalid command name ping." Looking for help in getting that functionality to work as well if possible!


CEO & Founder of Twisted Tactics.

 

In-game

Multi: Veles or Elixir

1-alt: Liability

 


#2 Angelus

Angelus
  • Members
  • 1202 posts

Posted 11 June 2014 - 04:02 PM

Never used this before, check out: http://stackoverflow...ted-with-tcl-tk

 

Can't give much advice other then making what you have somewhat work:

 

lappend iplist 
set y 0 
 
puts "This script will ping each address that you specify." 
puts -nonewline "How many IP’s will you enter? : " 
flush stdout 
gets stdin numberof 
 
puts "" 
 
for {set x 0} {$x<$numberof} {incr x} { 
  incr y 
  puts -nonewline "IP Address " 
  puts -nonewline $y 
  puts -nonewline " : " 
  flush stdout 
  gets stdin enteredip
  lappend iplist $enteredip
 
 
foreach item $iplist { 
  puts $item 

 

Removed the ping command, quick google shows people using scripts like these on their routers. Not sure what you need to make pinging work.


Edited by Angelus, 11 June 2014 - 04:03 PM.

Angelus ingame.
Back into the shadows once again...




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users