-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_action-1.0.sh
executable file
·62 lines (57 loc) · 1.78 KB
/
router_action-1.0.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/expect
#####################################################################################################################
#
# router_action-1.1.sh
#
# Author : Spyridakis Christos
# Created Date : 1/4/2019
# Last Updated : 1/4/2019
# Email : spyridakischristos@gmail.com
#
# Description :
# This script uses telnet protocol in order to establish a connection with your router
# and execute a predefined action (e.g. reboot)
#
# Additional Comments :
# The expected messages may vary based on router. In order to use this script
# without problems, you need to connect to your router once using a terminal
# and change expect messages as needed
#
# Dependences :
# - expect
# If you are in a Debian-Based system install it by executing:
# sudo apt-get install expect
#
####################################################################################################################
set timeout 20
set echo off
#----------------------------------------
# Initialize variables
#----------------------------------------
# CHANGE BELOW VARIABLES' VALUES
# ACCORDING TO YOUR NEEDS
#
# Device's IP address
set routerip 192.168.X.X
# Use your username
set name username
# Use your password
set pass password
# Desired action
set comd reboot
#----------------------------------------
# Establish connection
#----------------------------------------
spawn telnet ${routerip}
#----------------------------------------
# Authenticate user and send command
# ----------------------------------------
# Send username
expect "Login: " #sleep .1;
send "${name}\r"
# Send password
expect "Password: "
send "${pass}\r"
# Send action
expect ">"
send "${comd}\r"