Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sending "ping" output to a variable

I am trying to ping some ip addresses in my router. I use this code:

for {set n 0} {$n < 10} {incr n} {puts [exec "ping 199.99.$n.1]}

but this will show the output. the issue is that I don't want to see the output. I would like to send that output into another variable and the search the content of variable with "regexp" and get the result, and do the rest of the story. but I don't know how I can do that.

like image 511
Ahmad_R Avatar asked Sep 01 '26 08:09

Ahmad_R


1 Answers

Use the set command. The puts command prints it's argument.

set pingOutput [exec ping "199.99.$n.1"]

Or append if you want all IP's results in one variable.

set allPingOutput ""
for {set n 0} {$n < 10} {incr n} {
    append allPingOutput [exec ping "199.99.$n.1"]
}
like image 163
potrzebie Avatar answered Sep 04 '26 00:09

potrzebie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!