0

I figured out how to enable/disable my wireless connection with telnet, but I want to automate it.

I read telnet is not suitable for this, and one should use netcat instead.

This is what I have:

nc 192.168.1.254 23 << EOF
username
password
:wireless ifconfig state=$1
EOF

But when I run that I get something like:

????????Username : Administratorfietspomp:wireless i

Some searching turned up the -t and -i options, but neither help very much.

update

Expect it is:

#!/usr/bin/expect -f

set force_conservative 0  ;# set to 1 to force conservative mode even if
              ;# script wasn't run conservatively originally
if {$force_conservative} {
    set send_slow {1 .1}
    proc send {ignore arg} {
        sleep .1
        exp_send -s -- $arg
    }
}

if { [lindex $argv 0] == 1} {
    set status "enabled"
} else {
    set status "disabled"
}

set timeout -1
spawn telnet 192.168.1.254
match_max 100000
expect -exact "Username : "
send -- "username\r"
expect -exact "Password : "
send -- "password\r"
expect -exact "_{Administrator}=>"
send -- ":wireless ifconfig state=$status\r"
expect *
send -- "exit\r"
expect eof
Pepijn
  • 133
  • 6

1 Answers1

0

Use autoexpect. If you don't have that command already, install package expect.

Then just enter autoexpect and hit enter. Whatever you enter next will be saved as script.exp. When you are finished, hit Ctrl+d.

Finally you can run the automated version with expect ./script.exp. Of course you can rename the script.exp and move it wherever you want.

Janne Pikkarainen
  • 31,852
  • 4
  • 58
  • 81
  • Any idea how to get `autoexpect` on Mac? DuckGo turned up nothing. `expect` is installed though, so I could try to write it by hand. – Pepijn Oct 26 '11 at 10:20
  • Does this ancient link help you? https://discussions.apple.com/thread/418636?start=0&tstart=0 – Janne Pikkarainen Oct 26 '11 at 10:23
  • No, some idiot redirected the page to his Linkedin profile, and I can't find the Tcl folder on my Mac. – Pepijn Oct 26 '11 at 10:40