Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rm-pythonScripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
network-tools
rm-pythonScripts
Commits
a758a00c
Commit
a758a00c
authored
2 years ago
by
rick.mollard
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
bfd5c670
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
PortFlipper.py
+108
-0
108 additions, 0 deletions
PortFlipper.py
with
108 additions
and
0 deletions
PortFlipper.py
0 → 100644
+
108
−
0
View file @
a758a00c
from
urllib3
import
exceptions
# Prevent SSL Self-Signed Certificate Error
import
requests
# Creation Of New Object
import
urllib3
from
netmiko
import
(
ConnectHandler
,
NetmikoTimeoutException
)
# SSH Connection
import
socket
# DNS Lookup
import
time
# For Waiting
import
CampusSelector
import
SwitchCommands
def
main
(
ArubaUsername
,
ArubaPassword
):
urllib3
.
disable_warnings
(
urllib3
.
exceptions
.
InsecureRequestWarning
)
# Disable Certificate Warning
# Get the Campus or Switch IP Address
campus
=
CampusSelector
.
Campus_Selector
()
ip
=
campus
[
1
]
campus_selection
=
campus
[
2
]
campus
=
campus
[
0
]
# Get the Role we want to bounce
role
=
CampusSelector
.
Role_Selector
()
if
campus_selection
==
"
6
"
:
hostname
=
socket
.
getfqdn
(
ip
)
print
(
'
Current Switch:
'
,
hostname
,
"
:
"
,
ip
)
# Create Session Object
session
=
requests
.
session
()
# Create SSH Connection
ssh
=
ConnectHandler
(
device_type
=
"
aruba_procurve
"
,
host
=
ip
,
username
=
ArubaUsername
,
password
=
ArubaPassword
,
)
try
:
cli
=
ssh
.
send_command
(
f
"
show port-access clients
"
)
parse
=
cli
.
split
(
"
\n
"
)
for
line
in
parse
:
line
=
line
.
lstrip
()
if
role
in
line
:
interface
=
line
.
split
(
"
"
)[
0
]
if
interface
==
'
d
'
:
interface
=
line
.
split
(
"
"
)[
1
]
print
(
"
Non-Tunneled Device, Skip:
"
,
interface
)
else
:
interface
=
line
.
split
(
"
"
)[
0
]
# int_config = [f'interface {interface}', 'shut']
SwitchCommands
.
shutport
(
ssh
,
interface
)
# config_send = ssh.send_config_set(int_config)
print
(
"
Sending Command:
"
,
interface
,
"
\n
Port Shutdown - Waiting 2 Seconds
"
)
# int_config = [f'interface {interface}', 'no shut']
SwitchCommands
.
noshutport
(
ssh
,
interface
)
# config_send = ssh.send_config_set(int_config)
print
(
"
Sending Command:
"
,
interface
,
"
\n
Flipped - Waiting 1 Second For Next Port
"
)
finally
:
print
(
"
Logging Out From Switch
"
,
hostname
,
ip
)
ssh
.
disconnect
()
time
.
sleep
(
1
)
if
campus_selection
!=
"
6
"
:
with
open
(
campus
)
as
file
:
while
line
:
=
file
.
readline
().
rstrip
():
ip
=
line
hostname
=
socket
.
getfqdn
(
ip
)
print
(
'
Current Switch:
'
,
hostname
,
"
:
"
,
ip
)
# Create Session Object
session
=
requests
.
session
()
# Create SSH Connection
try
:
ssh
=
ConnectHandler
(
device_type
=
"
aruba_procurve
"
,
host
=
ip
,
username
=
ArubaUsername
,
password
=
ArubaPassword
,
)
try
:
cli
=
ssh
.
send_command
(
f
"
show port-access clients
"
)
parse
=
cli
.
split
(
"
\n
"
)
for
line
in
parse
:
line
=
line
.
lstrip
()
if
role
in
line
:
interface
=
line
.
split
(
"
"
)[
0
]
if
interface
==
'
d
'
:
interface
=
line
.
split
(
"
"
)[
1
]
print
(
"
Non-Tunneled Device, Skip:
"
,
interface
)
else
:
interface
=
line
.
split
(
"
"
)[
0
]
# int_config = [f'interface {interface}', 'shut']
SwitchCommands
.
shutport
(
ssh
,
interface
)
# config_send = ssh.send_config_set(int_config)
print
(
"
Sending Command:
"
,
interface
,
"
\n
Port Shutdown - Waiting 2 Seconds
"
)
# int_config = [f'interface {interface}', 'no shut']
SwitchCommands
.
noshutport
(
ssh
,
interface
)
# config_send = ssh.send_config_set(int_config)
print
(
"
Sending Command:
"
,
interface
,
"
\n
Flipped - Waiting 1 Second For Next Port
"
)
finally
:
print
(
"
Logging Out From Switch
"
,
hostname
,
ip
)
ssh
.
disconnect
()
except
(
NetmikoTimeoutException
)
as
error
:
print
(
"
Switch is not responding----->
"
+
ip
)
print
(
"
Switch is not responding----->
"
+
ip
)
print
(
"
Switch is not responding----->
"
+
ip
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment