Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Switcheversenken
Switcheversenken Scripts
Commits
81a93df9
Verified
Commit
81a93df9
authored
Sep 19, 2021
by
Jenny
Browse files
added configure_switch for 54xx switches
parent
54a769f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
configure_switch.py
→
switchconfig/
configure_switch.py
View file @
81a93df9
File moved
switchconfig/configure_switch_54.py
0 → 100755
View file @
81a93df9
#!/usr/bin/env python3
import
argparse
import
os
import
sys
start
=
"""
#!/usr/bin/expect -f
set timeout 10
spawn telnet {switch_ip}
expect "Press any key to continue"
send "
\\
r"
expect "#"
send "configure
\\
r"
expect "(config)"
send "snmp-server host {server_ip} community {snmp_community} trap-level all
\\
r"
"""
end
=
"""
expect "(config)"
send "write memory
\\
r"
expect "(config)"
send "logout
\\
r"
expect "Do you want to log out"
send "y
\\
r"
"""
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Configure a SWV-Switch (Version for 54XX Switches)'
)
parser
.
add_argument
(
'switch_ip'
,
type
=
str
,
help
=
'IP of the Switch'
)
parser
.
add_argument
(
'server_ip'
,
type
=
str
,
help
=
'IP of the SNMP-Server'
)
parser
.
add_argument
(
'snmp_community'
,
type
=
str
,
help
=
'SNMP-Community-String'
)
args
=
parser
.
parse_args
()
content
=
start
+
"
\n
"
ctr
=
1200
for
i
in
(
'A'
,
'C'
,
'E'
):
for
j
in
range
(
1
,
25
):
content
+=
'expect "(config)"
\n
'
content
+=
'send "vlan '
+
str
(
ctr
)
+
' untagged '
+
i
+
str
(
j
)
+
'
\\
r"
\n
'
ctr
=
ctr
+
1
content
+=
end
content
=
content
.
format
(
switch_ip
=
args
.
switch_ip
,
server_ip
=
args
.
server_ip
,
snmp_community
=
args
.
snmp_community
)
outfile
=
open
(
"/tmp/switchconfig.expect"
,
"w"
)
outfile
.
write
(
content
)
outfile
.
close
()
os
.
system
(
"expect -f /tmp/switchconfig.expect"
)
if
__name__
==
'__main__'
:
sys
.
exit
(
main
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment