Skip to content

Instantly share code, notes, and snippets.

@leonroy
Created May 29, 2016 13:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save leonroy/a7a53cb1b91e90fe9fd3eb9776ac3f29 to your computer and use it in GitHub Desktop.
Save leonroy/a7a53cb1b91e90fe9fd3eb9776ac3f29 to your computer and use it in GitHub Desktop.
SSH to HP 1920 and enable cmdline-mode
#!/usr/bin/expect -f
set timeout 60
set host [lindex $argv 0]
stty -echo
send_user -- "Password for $host: "
expect_user -re "(.*)\n"
send_user "\n"
stty echo
set password $expect_out(1,string)
eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $host
expect "assword:"
send "$password\r"
# Enable Command Line Mode
send "_cmdline-mode on\r"
expect "\[Y\/N\]"
send "Y\r"
expect "assword:"
send "Jinhua1920unauthorized\r"
interact
@devZer0
Copy link

devZer0 commented Jul 7, 2017

Hi, i found this information useful, as i was searching for a way to get information from hp1920 
which port has learned which mac (for network intrusion).

I was pulling my hair out to get this via snmp, apparently its not possible - so lets do the expect approach.... ;)

maybe somone finds this useful - it did take me a while to find appropriate commands...

# cat ./hp1920_getmacs.exp
#!/usr/bin/expect -f
set timeout 60
set host [lindex $argv 0]
set user [lindex $argv 1]
set pass [lindex $argv 2]

stty echo
eval spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no $user@$host
expect "password:"
send "$pass\r"
expect ""
send "_cmdline-mode on\r"
expect "\[Y\/N\]"
send "Y\r"
expect "password:"
send "Jinhua1920unauthorized\r"
expect ""
send "screen-length disable\r"
expect ""
send "display mac-address\r"
expect ""


# ./hp1920_getmacs.exp  admin admin
spawn ssh -oStrictHostKeyChecking=no -oCheckHostIP=no admin@
admin@'s password:

******************************************************************************
* Copyright (c) 2010-2016 Hewlett Packard Enterprise Development LP          *
* Without the owner's prior written consent,                                 *
* no decompiling or reverse-engineering shall be allowed.                    *
******************************************************************************

_cmdline-mode on
All commands can be displayed and executed. Continue? [Y/N]Y
Please input password:**********************
Warning: Now you enter an all-command mode for developer's testing, some commands may affect operation by 
wrong use, please carefully use it with our engineer's direction.
screen-length disable
% Screen-length configuration is disabled for current user.
display mac-address
MAC ADDR        VLAN ID  STATE           PORT INDEX                AGING TIME(s)
feed-dead-beef  1        Learned         GigabitEthernet1/0/1      AGING
face-b00c-face  1        Learned         GigabitEthernet1/0/20     AGING


 --- 2 mac address(es) found ---


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment