Skip to content

Instantly share code, notes, and snippets.

@jostmart
Created March 15, 2021 07:30
Show Gist options
  • Save jostmart/45df21911e679d353676be164e801313 to your computer and use it in GitHub Desktop.
Save jostmart/45df21911e679d353676be164e801313 to your computer and use it in GitHub Desktop.
#!/usr/bin/expect
# Set up various other variables here ($user, $password)
set user admin
set password xxxxx30r8fd
# Skapa en fil för lagring av resultat
set outfile [open ./TELNET-RESULTS.txt w]
puts $outfile "--( start )-----------------"
set fp [open hosts.txt r]
while {[gets $fp ip] != -1} {
# Try to connect
spawn telnet $ip
# Handle connection result
expect {
-re "Operation timed out|Unable to connect to remote host|Connection refused" {
puts $outfile "$ip TELNET FAILED"
}
-re "Username:|ubnt login:" {
send "$user\r"
expect "Password:" {
send "$password\r"
}
expect {
-re "# |ubnt:" {
send "exit\r"
puts $outfile "$ip TELNET SUCCESS"
}
"Login incorrect" {
puts $outfile "$ip LOGIN INCORRECT"
}
}
}
timeout {
puts $outfile "$ip TELNET timeout"
}
}
}
close $fp
# Stäng resultatfilen
puts $outfile "--( Stop )-----------------"
close $outfile
cat TELNET-RESULTS.txt C02XH3YMJG5H: Mon Mar 15 08:29:57 2021
--( start )-----------------
192.168.1.1 TELNET SUCCESS
1.1.1.1 TELNET timeout
192.168.1.165 TELNET FAILED
--( Stop )-----------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment