├── LICENSE ├── README.md ├── arista ├── README.md ├── goeapi │ ├── .eapi.conf │ ├── README.md │ ├── archive │ │ ├── show_cmds_output.txt │ │ └── show_cmds_output2.txt │ ├── change_config │ │ ├── go.mod │ │ ├── go.sum │ │ └── main.go │ ├── deploy_lab_cfgs │ │ ├── README.md │ │ └── main.go │ └── show_commands │ │ ├── go,mod │ │ ├── go.sum │ │ └── show_cmds.go ├── http_client │ ├── config_script.go │ ├── config_script_output.txt │ ├── config_script_output2.txt │ ├── config_script_v2.go │ └── config_script_v2_output.txt ├── lab_setup │ └── ceoslab_6_devices Diagram.drawio.png └── ssh_client │ ├── README.md │ ├── go.mod │ ├── go.sum │ └── main.go ├── http_client ├── PostCmds.go ├── host_file001.txt ├── host_file002.txt ├── httpGet_v1.go ├── httpGet_v1_output.txt ├── httpGet_v2.go ├── httpGet_v2_output.txt ├── httpPost_v1.go ├── httpPost_v1_output.txt ├── httpPost_v2.go ├── httpPost_v2_output.txt ├── httpPost_v3.go └── httpPost_v3_output.txt ├── misc_folder ├── cli_args.go ├── methodsTest.go ├── methodsTest_output.txt ├── struct_switch_break_loop.go └── struct_switch_break_loop_output.txt ├── scp_client ├── README.md ├── archive │ ├── hello.txt │ └── scp_client_v1.go ├── copy_dir │ └── scp_clientv3.go ├── go.mod ├── go.sum └── main.go ├── ssh_client ├── pre_go.mod_stuff │ ├── can_I_ssh_script.go │ ├── can_I_ssh_script_output.txt │ ├── cmd_file.txt │ ├── cmd_file001.txt │ ├── cmd_file2.txt │ ├── go_ssh_script_2.go │ ├── go_ssh_script_2_output.txt │ ├── go_ssh_script_3.go │ ├── go_ssh_script_3_output.txt │ ├── host_file001.txt │ ├── interactive_ssh.go │ ├── interactive_ssh_output.txt │ ├── ios-xe-mgmt-latest.cisco.com\:8181.cfg │ ├── ios-xe-mgmt.cisco.com\:8181.cfg │ ├── sbx-nxos-mgmt.cisco.com\:8181.cfg │ ├── ssh_client_script_10.go │ ├── ssh_client_script_10_output.txt │ ├── ssh_multi_cmd.go │ ├── ssh_multi_cmd_output.txt │ ├── ssh_use_cmd_file.go │ ├── ssh_use_cmd_file_output.txt │ ├── ssh_use_host_cmd_file_output_V2.txt │ ├── ssh_use_host_cmd_files_V2.go │ ├── ssh_use_stdin.go │ ├── ssh_use_stdin_output.txt │ ├── ssh_use_stdin_output_2.txt │ ├── ssh_using_cli_args.go │ ├── ssh_using_cli_args_output.txt │ ├── ssh_using_host_cmd_files.go │ └── ssh_using_host_cmd_files_output.txt ├── runcli │ ├── README.md │ ├── go.mod │ ├── go.sum │ └── runcli.go ├── runscript │ ├── README.md │ ├── go.mod │ ├── go.sum │ └── runscript.go ├── ssh_cli_client │ ├── README.md │ ├── go.mod │ ├── go.sum │ └── main.go └── ssh_client │ ├── README.md │ ├── file_fastxe:22.cfg │ ├── file_nxos:8181.cfg │ ├── go.mod │ ├── go.sum │ ├── group1.txt │ ├── group2.txt │ └── main.go └── using_go_mod_example.txt /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Todd Riemenschneider 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /arista/README.md: -------------------------------------------------------------------------------- 1 | ### Arista 2 | 3 | - Using ceoslab for testing. 4 | 5 | - Sample code repository. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /arista/goeapi/.eapi.conf: -------------------------------------------------------------------------------- 1 | [connection:ceos1] 2 | 3 | host=172.17.0.2 4 | 5 | username=arista 6 | 7 | password=arista 8 | 9 | transport=https 10 | 11 | 12 | 13 | 14 | 15 | [connection:ceos2] 16 | 17 | host=172.17.0.3 18 | 19 | username=arista 20 | 21 | password=arista 22 | 23 | transport=https 24 | 25 | 26 | 27 | 28 | [connection:ceos3] 29 | 30 | host=172.17.0.4 31 | 32 | username=arista 33 | 34 | password=arista 35 | 36 | transport=https 37 | 38 | 39 | 40 | 41 | [connection:ceos4] 42 | 43 | host=172.17.0.5 44 | 45 | username=arista 46 | 47 | password=arista 48 | 49 | transport=https 50 | 51 | 52 | 53 | 54 | [connection:ceos5] 55 | 56 | host=172.17.0.6 57 | 58 | username=arista 59 | 60 | password=arista 61 | 62 | transport=https 63 | 64 | 65 | 66 | 67 | [connection:ceos6] 68 | 69 | host=172.17.0.7 70 | 71 | username=arista 72 | 73 | password=arista 74 | 75 | transport=https 76 | -------------------------------------------------------------------------------- /arista/goeapi/README.md: -------------------------------------------------------------------------------- 1 | ### GoEAPI 2 | I found that the goeapi documentation was rather sparse. It was decent for show commands but configuration documentation was lacking. After playing around with it and looking at go.dev package documentation I got a feel for what it was capable of. I did sort out how to use it for configuration. I definately feel like this framework could use some attention. Doesn't appear to be actively updated. 3 | 4 | Between pyeapi and goeapi I would probably stick with pyeapi. It is useable though. 5 | 6 | 7 | 8 | - Sample config change 9 | ``` 10 | /* 11 | twr14152@DESKTOP-S55FNN9:~/code_folder/go_folder/misc/goeapi/change_config$ go run main.go 12 | Connected to ceos1 13 | 14 | 15 | 16 | Pre-Change state: 17 | 18 | 19 | [map[command:show ip interface brief result:Address 20 | Interface IP Address Status Protocol MTU Owner 21 | --------------- ------------------ ----------- ------------- ---------- ------- 22 | Loopback0 1.1.1.1/32 up up 65535 23 | Management0 172.17.0.2/16 up up 1500]] 24 | true 25 | 26 | 27 | 28 | Post change state: 29 | 30 | 31 | [map[command:show ip interface brief result:Address 32 | Interface IP Address Status Protocol MTU Owner 33 | --------------- ------------------ ----------- ------------- ---------- ------- 34 | Loopback0 1.1.1.1/32 up up 65535 35 | Loopback55 55.55.55.55/32 up up 65535 36 | Management0 172.17.0.2/16 up up 1500]] 37 | 38 | 39 | ------------------------------- 40 | 41 | Connected to ceos2 42 | 43 | 44 | 45 | Pre-Change state: 46 | 47 | 48 | [map[command:show ip interface brief result:Address 49 | Interface IP Address Status Protocol MTU Owner 50 | --------------- ------------------ ----------- ------------- ---------- ------- 51 | Loopback0 2.2.2.2/32 up up 65535 52 | Loopback69 unassigned up up 65535 53 | Management0 172.17.0.3/16 up up 1500]] 54 | true 55 | 56 | 57 | 58 | Post change state: 59 | 60 | 61 | [map[command:show ip interface brief result:Address 62 | Interface IP Address Status Protocol MTU Owner 63 | --------------- ------------------ ----------- ------------- ---------- ------- 64 | Loopback0 2.2.2.2/32 up up 65535 65 | Loopback55 55.55.55.55/32 up up 65535 66 | Loopback69 unassigned up up 65535 67 | Management0 172.17.0.3/16 up up 1500]] 68 | 69 | 70 | ------------------------------- 71 | 72 | Connected to ceos3 73 | 74 | 75 | 76 | Pre-Change state: 77 | 78 | 79 | [map[command:show ip interface brief result:Address 80 | Interface IP Address Status Protocol MTU Owner 81 | --------------- ------------------ ----------- ------------- ---------- ------- 82 | Loopback0 3.3.3.3/32 up up 65535 83 | Management0 172.17.0.4/16 up up 1500]] 84 | true 85 | 86 | 87 | 88 | Post change state: 89 | 90 | 91 | [map[command:show ip interface brief result:Address 92 | Interface IP Address Status Protocol MTU Owner 93 | --------------- ------------------ ----------- ------------- ---------- ------- 94 | Loopback0 3.3.3.3/32 up up 65535 95 | Loopback55 55.55.55.55/32 up up 65535 96 | Management0 172.17.0.4/16 up up 1500]] 97 | 98 | 99 | ------------------------------- 100 | 101 | Connected to ceos4 102 | 103 | 104 | 105 | Pre-Change state: 106 | 107 | 108 | [map[command:show ip interface brief result:Address 109 | Interface IP Address Status Protocol MTU Owner 110 | --------------- ------------------ ----------- ------------- ---------- ------- 111 | Loopback0 4.4.4.4/32 up up 65535 112 | Management0 172.17.0.5/16 up up 1500]] 113 | true 114 | 115 | 116 | 117 | Post change state: 118 | 119 | 120 | [map[command:show ip interface brief result:Address 121 | Interface IP Address Status Protocol MTU Owner 122 | --------------- ------------------ ----------- ------------- ---------- ------- 123 | Loopback0 4.4.4.4/32 up up 65535 124 | Loopback55 55.55.55.55/32 up up 65535 125 | Management0 172.17.0.5/16 up up 1500]] 126 | 127 | 128 | ------------------------------- 129 | 130 | Connected to ceos5 131 | 132 | 133 | 134 | Pre-Change state: 135 | 136 | 137 | [map[command:show ip interface brief result:Address 138 | Interface IP Address Status Protocol MTU Owner 139 | --------------- ------------------ ----------- ------------- ---------- ------- 140 | Loopback0 5.5.5.5/32 up up 65535 141 | Management0 172.17.0.6/16 up up 1500]] 142 | true 143 | 144 | 145 | 146 | Post change state: 147 | 148 | 149 | [map[command:show ip interface brief result:Address 150 | Interface IP Address Status Protocol MTU Owner 151 | --------------- ------------------ ----------- ------------- ---------- ------- 152 | Loopback0 5.5.5.5/32 up up 65535 153 | Loopback55 55.55.55.55/32 up up 65535 154 | Management0 172.17.0.6/16 up up 1500]] 155 | 156 | 157 | ------------------------------- 158 | 159 | Connected to ceos6 160 | 161 | 162 | 163 | Pre-Change state: 164 | 165 | 166 | [map[command:show ip interface brief result:Address 167 | Interface IP Address Status Protocol MTU Owner 168 | --------------- ------------------ ----------- ------------- ---------- ------- 169 | Loopback0 6.6.6.6/32 up up 65535 170 | Management0 172.17.0.7/16 up up 1500]] 171 | true 172 | 173 | 174 | 175 | Post change state: 176 | 177 | 178 | [map[command:show ip interface brief result:Address 179 | Interface IP Address Status Protocol MTU Owner 180 | --------------- ------------------ ----------- ------------- ---------- ------- 181 | Loopback0 6.6.6.6/32 up up 65535 182 | Loopback55 55.55.55.55/32 up up 65535 183 | Management0 172.17.0.7/16 up up 1500]] 184 | 185 | 186 | ------------------------------- 187 | 188 | twr14152@DESKTOP-S55FNN9:~/code_folder/go_folder/misc/goeapi/change_config$ 189 | */ 190 | ``` 191 | 192 | - sample of the show commands 193 | ``` 194 | twr14152@DESKTOP-S55FNN9:~/code_folder/go_folder/misc/goeapi/show_commands$ go run main.go show version, show ip interface brief 195 | [show version show ip interface brief] 196 | Connected to ceos1 197 | [map[command:show version result:Arista cEOSLab 198 | Hardware version: 199 | Serial number: 200 | Hardware MAC address: 0242.ac20.996c 201 | System MAC address: 0242.ac20.996c 202 | 203 | Software image version: 4.30.5M-35156751.4305M (engineering build) 204 | Architecture: x86_64 205 | Internal build version: 4.30.5M-35156751.4305M 206 | Internal build ID: 29383dc6-2c4f-445b-8162-1209cd1b57df 207 | Image format version: 1.0 208 | Image optimization: None 209 | 210 | cEOS tools version: (unknown) 211 | Kernel version: 5.15.146.1-microsoft-standard-WSL2 212 | 213 | Uptime: 4 days, 4 hours and 56 minutes 214 | Total memory: 8108944 kB 215 | Free memory: 916656 kB] map[command: show ip interface brief result:Address 216 | Interface IP Address Status Protocol MTU Owner 217 | --------------- ------------------ ----------- ------------- ---------- ------- 218 | Loopback0 1.1.1.1/32 up up 65535 219 | Loopback55 55.55.55.55/32 up up 65535 220 | Management0 172.17.0.2/16 up up 1500]] 221 | 222 | 223 | 224 | 225 | Connected to ceos2 226 | [map[command:show version result:Arista cEOSLab 227 | Hardware version: 228 | Serial number: 229 | Hardware MAC address: 0242.ac97.38c5 230 | System MAC address: 0242.ac97.38c5 231 | 232 | Software image version: 4.30.5M-35156751.4305M (engineering build) 233 | Architecture: x86_64 234 | Internal build version: 4.30.5M-35156751.4305M 235 | Internal build ID: 29383dc6-2c4f-445b-8162-1209cd1b57df 236 | Image format version: 1.0 237 | Image optimization: None 238 | 239 | cEOS tools version: (unknown) 240 | Kernel version: 5.15.146.1-microsoft-standard-WSL2 241 | 242 | Uptime: 4 days, 4 hours and 56 minutes 243 | Total memory: 8108944 kB 244 | Free memory: 916656 kB] map[command: show ip interface brief result:Address 245 | Interface IP Address Status Protocol MTU Owner 246 | --------------- ------------------ ----------- ------------- ---------- ------- 247 | Loopback0 2.2.2.2/32 up up 65535 248 | Loopback55 55.55.55.55/32 up up 65535 249 | Loopback69 unassigned up up 65535 250 | Management0 172.17.0.3/16 up up 1500]] 251 | 252 | 253 | 254 | 255 | Connected to ceos3 256 | [map[command:show version result:Arista cEOSLab 257 | Hardware version: 258 | Serial number: 259 | Hardware MAC address: 0242.ac53.f242 260 | System MAC address: 0242.ac53.f242 261 | 262 | Software image version: 4.30.5M-35156751.4305M (engineering build) 263 | Architecture: x86_64 264 | Internal build version: 4.30.5M-35156751.4305M 265 | Internal build ID: 29383dc6-2c4f-445b-8162-1209cd1b57df 266 | Image format version: 1.0 267 | Image optimization: None 268 | 269 | cEOS tools version: (unknown) 270 | Kernel version: 5.15.146.1-microsoft-standard-WSL2 271 | 272 | Uptime: 4 days, 4 hours and 56 minutes 273 | Total memory: 8108944 kB 274 | Free memory: 916656 kB] map[command: show ip interface brief result:Address 275 | Interface IP Address Status Protocol MTU Owner 276 | --------------- ------------------ ----------- ------------- ---------- ------- 277 | Loopback0 3.3.3.3/32 up up 65535 278 | Loopback55 55.55.55.55/32 up up 65535 279 | Management0 172.17.0.4/16 up up 1500]] 280 | 281 | 282 | 283 | 284 | Connected to ceos4 285 | [map[command:show version result:Arista cEOSLab 286 | Hardware version: 287 | Serial number: 288 | Hardware MAC address: 0242.ac6b.0386 289 | System MAC address: 0242.ac6b.0386 290 | 291 | Software image version: 4.30.5M-35156751.4305M (engineering build) 292 | Architecture: x86_64 293 | Internal build version: 4.30.5M-35156751.4305M 294 | Internal build ID: 29383dc6-2c4f-445b-8162-1209cd1b57df 295 | Image format version: 1.0 296 | Image optimization: None 297 | 298 | cEOS tools version: (unknown) 299 | Kernel version: 5.15.146.1-microsoft-standard-WSL2 300 | 301 | Uptime: 4 days, 4 hours and 56 minutes 302 | Total memory: 8108944 kB 303 | Free memory: 916656 kB] map[command: show ip interface brief result:Address 304 | Interface IP Address Status Protocol MTU Owner 305 | --------------- ------------------ ----------- ------------- ---------- ------- 306 | Loopback0 4.4.4.4/32 up up 65535 307 | Loopback55 55.55.55.55/32 up up 65535 308 | Management0 172.17.0.5/16 up up 1500]] 309 | 310 | 311 | 312 | 313 | Connected to ceos5 314 | [map[command:show version result:Arista cEOSLab 315 | Hardware version: 316 | Serial number: 317 | Hardware MAC address: 0242.ac92.2c1a 318 | System MAC address: 0242.ac92.2c1a 319 | 320 | Software image version: 4.30.5M-35156751.4305M (engineering build) 321 | Architecture: x86_64 322 | Internal build version: 4.30.5M-35156751.4305M 323 | Internal build ID: 29383dc6-2c4f-445b-8162-1209cd1b57df 324 | Image format version: 1.0 325 | Image optimization: None 326 | 327 | cEOS tools version: (unknown) 328 | Kernel version: 5.15.146.1-microsoft-standard-WSL2 329 | 330 | Uptime: 1 day, 16 hours and 25 minutes 331 | Total memory: 8108944 kB 332 | Free memory: 916560 kB] map[command: show ip interface brief result:Address 333 | Interface IP Address Status Protocol MTU Owner 334 | --------------- ------------------ ----------- ------------- ---------- ------- 335 | Loopback0 5.5.5.5/32 up up 65535 336 | Loopback55 55.55.55.55/32 up up 65535 337 | Management0 172.17.0.6/16 up up 1500]] 338 | 339 | 340 | 341 | 342 | Connected to ceos6 343 | [map[command:show version result:Arista cEOSLab 344 | Hardware version: 345 | Serial number: 346 | Hardware MAC address: 0242.ac07.09bd 347 | System MAC address: 0242.ac07.09bd 348 | 349 | Software image version: 4.30.5M-35156751.4305M (engineering build) 350 | Architecture: x86_64 351 | Internal build version: 4.30.5M-35156751.4305M 352 | Internal build ID: 29383dc6-2c4f-445b-8162-1209cd1b57df 353 | Image format version: 1.0 354 | Image optimization: None 355 | 356 | cEOS tools version: (unknown) 357 | Kernel version: 5.15.146.1-microsoft-standard-WSL2 358 | 359 | Uptime: 1 day, 16 hours and 25 minutes 360 | Total memory: 8108944 kB 361 | Free memory: 916560 kB] map[command: show ip interface brief result:Address 362 | Interface IP Address Status Protocol MTU Owner 363 | --------------- ------------------ ----------- ------------- ---------- ------- 364 | Loopback0 6.6.6.6/32 up up 65535 365 | Loopback55 55.55.55.55/32 up up 65535 366 | Management0 172.17.0.7/16 up up 1500]] 367 | 368 | 369 | 370 | 371 | twr14152@DESKTOP-S55FNN9:~/code_folder/go_folder/misc/goeapi/show_commands$ 372 | ``` 373 | -------------------------------------------------------------------------------- /arista/goeapi/archive/show_cmds_output2.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ go run show_cmds.go write memory 2 | [write memory] 3 | ############################# 4 | Connected to ceos1 5 | [map[command:write memory result:Copy completed successfully.]] 6 | ############################ 7 | ############################# 8 | Connected to ceos2 9 | [map[command:write memory result:Copy completed successfully.]] 10 | ############################ 11 | ############################# 12 | Connected to ceos3 13 | [map[command:write memory result:Copy completed successfully.]] 14 | ############################ 15 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ 16 | 17 | Connected to ceos1 18 | [map[command:show startup-config result:! Command: show startup-config 19 | ! Startup-config last modified at Mon Feb 3 11:19:54 2020 by arista 20 | ! device: ceos1 (cEOSSim, EOS-4.20.5F) 21 | ! 22 | transceiver qsfp default-mode 4x10G 23 | ! 24 | hostname ceos1 25 | ip domain lookup source-interface Loopback1 26 | ip name-server vrf default 8.8.8.8 27 | ! 28 | spanning-tree mode mstp 29 | ! 30 | no aaa root 31 | ! 32 | username arista privilege 15 secret sha512 $6$s/zsPG3v9LhN2SPO$QfehiEL7kuFzut0KZ8nG2OjipoRL7HvdOu23QPw7X.A9CZWVY.gKUayVykc83ObYdzY2By/1KAayo154Je/Bm. 33 | ! 34 | interface Ethernet1 35 | no switchport 36 | ip address 10.0.0.1/24 37 | ! 38 | interface Ethernet2 39 | ! 40 | interface Ethernet3 41 | ! 42 | interface Loopback1 43 | description router-id 44 | ip address 1.1.1.1/32 45 | ! 46 | interface Loopback2 47 | ! 48 | ip routing 49 | ! 50 | router ospf 1 51 | router-id 1.1.1.1 52 | network 1.1.1.1/32 area 0.0.0.0 53 | network 10.0.0.0/24 area 0.0.0.0 54 | max-lsa 12000 55 | ! 56 | management api http-commands 57 | no shutdown 58 | ! 59 | end]] 60 | ############################ 61 | ############################# 62 | Connected to ceos2 63 | [map[command:show startup-config result:! Command: show startup-config 64 | ! Startup-config last modified at Mon Feb 3 11:19:54 2020 by arista 65 | ! device: ceos2 (cEOSSim, EOS-4.20.5F) 66 | ! 67 | transceiver qsfp default-mode 4x10G 68 | ! 69 | hostname ceos2 70 | ip domain lookup source-interface Loopback1 71 | ip name-server vrf default 8.8.8.8 72 | ! 73 | spanning-tree mode mstp 74 | ! 75 | no aaa root 76 | ! 77 | username arista privilege 15 secret sha512 $6$TRQ598fliEOez7f0$Z83fBpOhtq/yNMPYLCDUi057bO2/Bj6upB/mKrYe6WXZbUG3q3iHOv/BPP/V/U15kRoMfdgsKUWzTz2UxDdBE1 78 | ! 79 | interface Ethernet1 80 | no switchport 81 | ip address 10.0.0.2/24 82 | ! 83 | interface Ethernet2 84 | ! 85 | interface Ethernet3 86 | ! 87 | interface Loopback1 88 | description router-id 89 | ip address 2.2.2.2/32 90 | ! 91 | interface Loopback2 92 | ! 93 | ip routing 94 | ! 95 | router ospf 1 96 | router-id 2.2.2.2 97 | network 2.2.2.2/32 area 0.0.0.0 98 | network 10.0.0.0/24 area 0.0.0.0 99 | max-lsa 12000 100 | ! 101 | management api http-commands 102 | no shutdown 103 | ! 104 | end]] 105 | ############################ 106 | ############################# 107 | Connected to ceos3 108 | [map[command:show startup-config result:! Command: show startup-config 109 | ! Startup-config last modified at Mon Feb 3 11:19:54 2020 by arista 110 | ! device: ceos3 (cEOSSim, EOS-4.20.5F) 111 | ! 112 | transceiver qsfp default-mode 4x10G 113 | ! 114 | hostname ceos3 115 | ip domain lookup source-interface Loopback1 116 | ip name-server vrf default 8.8.8.8 117 | ! 118 | spanning-tree mode mstp 119 | ! 120 | no aaa root 121 | ! 122 | username arista privilege 15 secret sha512 $6$67F9M7DdHVJiqeDw$amdvAF1spLH4HLyAQp0nd9ygY4rA.rwPJXtbj18s5pRDaEYi1ORv4Bo1b3vyyMLGyxYQkAOtzZkQ3jsniUtaH0 123 | ! 124 | interface Ethernet1 125 | no switchport 126 | ip address 10.0.0.3/24 127 | ! 128 | interface Ethernet2 129 | ! 130 | interface Ethernet3 131 | ! 132 | interface Loopback1 133 | description router-id 134 | ip address 3.3.3.3/32 135 | ! 136 | interface Loopback2 137 | ! 138 | ip routing 139 | ! 140 | router ospf 1 141 | router-id 3.3.3.3 142 | network 3.3.3.3/32 area 0.0.0.0 143 | network 10.0.0.0/24 area 0.0.0.0 144 | max-lsa 12000 145 | ! 146 | management api http-commands 147 | no shutdown 148 | ! 149 | end]] 150 | ############################ 151 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ 152 | -------------------------------------------------------------------------------- /arista/goeapi/change_config/go.mod: -------------------------------------------------------------------------------- 1 | module change_config 2 | 3 | go 1.22.2 4 | 5 | require github.com/aristanetworks/goeapi v1.0.0 6 | 7 | require ( 8 | github.com/mitchellh/mapstructure v1.5.0 // indirect 9 | github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect 10 | ) 11 | -------------------------------------------------------------------------------- /arista/goeapi/change_config/go.sum: -------------------------------------------------------------------------------- 1 | github.com/aristanetworks/goeapi v1.0.0 h1:FjckkjOY32SkmKrqDyBqYu6hN7DaIJuxcii9LLdZqtQ= 2 | github.com/aristanetworks/goeapi v1.0.0/go.mod h1:DcgIvssM+qcRRVICDky/ecT/Gqpx40UQDTYY8Lu/iJ0= 3 | github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= 4 | github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 5 | github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks= 6 | github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw= 7 | -------------------------------------------------------------------------------- /arista/goeapi/change_config/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/aristanetworks/goeapi" 6 | ) 7 | 8 | //hosts to configure 9 | var HostList = []string{"ceos1", "ceos2", "ceos3", "ceos4", "ceos5", "ceos6"} 10 | 11 | func main() { 12 | 13 | //cmds := []string{"show running-config"} 14 | cmds1 := []string{"show ip interface brief"} 15 | 16 | // Configuration commands 17 | cfg1 := "interface loopback 55" 18 | cfg2 := "description testing goeapi" 19 | cfg3 := "ip address 55.55.55.55/32" 20 | //cfg4 := "no interface loopback 55" 21 | 22 | for _, host := range HostList { 23 | node, err := goeapi.ConnectTo(host) 24 | if err != nil { 25 | fmt.Println(err) 26 | } 27 | fmt.Printf("Connected to %v\n", host) 28 | fmt.Printf("\n\n\nPre-Change state:\n\n\n") 29 | fmt.Println(node.Enable(cmds1)) 30 | fmt.Println(node.Config(cfg1, cfg2, cfg3)) 31 | fmt.Printf("\n\n\nPost change state: \n\n\n") 32 | fmt.Println(node.Enable(cmds1)) 33 | fmt.Printf("\n\n-------------------------------\n\n") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /arista/goeapi/deploy_lab_cfgs/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/aristanetworks/goeapi" 6 | "log" 7 | "time" 8 | ) 9 | 10 | func deploy_ceos1() { 11 | 12 | host := "ceos1" 13 | cmds1 := []string{"show running-config"} 14 | cmds2 := []string{"show ip interface brief | json", "show ip ospf neighbor | json", "show ip bgp summary | json"} 15 | // Configuration commands 16 | c1 := "interface eth1" 17 | c2 := "no switchport" 18 | c3 := "ip address 10.0.0.1/24" 19 | c4 := "no shutdown" 20 | c5 := "router ospf 1" 21 | c6 := "network 10.0.0.0/24 area 0" 22 | c7 := "router bgp 100" 23 | c8 := "neighbor 2.2.2.2 remote-as 100" 24 | c9 := "neighbor 2.2.2.2 update-source loopback0" 25 | c10 := "router-id 1.1.1.1" 26 | c11 := "network 1.1.1.1 mask 255.255.255.255" 27 | c12 := "interface eth3" 28 | c13 := "no switchport" 29 | c14 := "no shutdown" 30 | c15 := "ip address 157.130.1.1/30" 31 | c16 := "router bgp 100" 32 | c17 := "neighbor 157.130.1.2 remote-as 300" 33 | c18 := "redistribute connected" 34 | node, err := goeapi.ConnectTo(host) 35 | if err != nil { 36 | log.Fatal(err) 37 | } 38 | fmt.Printf("Connected to %v\n", host) 39 | fmt.Printf("\n\n\nPre-Change state:\n\n\n") 40 | fmt.Println(node.Enable(cmds1)) 41 | fmt.Println(node.ConfigWithErr(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18)) 42 | fmt.Printf("\n\n\nPost-change state: \n\n\n") 43 | duration := time.Duration(15) * time.Second 44 | time.Sleep(duration) 45 | fmt.Println(node.Enable(cmds1)) 46 | fmt.Println(node.Enable(cmds2)) 47 | fmt.Printf("\n\n\n\n") 48 | } 49 | 50 | func deploy_ceos2() { 51 | 52 | host := "ceos2" 53 | cmds1 := []string{"show running-config"} 54 | cmds2 := []string{"show ip interface brief | json", "show ip ospf neighbor | json", "show ip bgp summary | json"} 55 | // Configuration commands 56 | c1 := "interface ethernet 1" 57 | c2 := "no switchport" 58 | c3 := "ip address 10.0.0.2/24" 59 | c4 := "no shutdown" 60 | c5 := "router ospf 1" 61 | c6 := "network 10.0.0.0/24 area 0" 62 | c7 := "router bgp 100" 63 | c8 := "neighbor 1.1.1.1 remote-as 100" 64 | c9 := "neighbor 1.1.1.1 update-source loopback 0" 65 | c10 := "router-id 2.2.2.2" 66 | c11 := "network 2.2.2.2 mask 255.255.255.255" 67 | c12 := "interface eth3" 68 | c13 := "no switchport" 69 | c14 := "no shutdown" 70 | c15 := "ip address 157.130.2.1/30" 71 | c16 := "router bgp 100" 72 | c17 := "neighbor 157.130.2.2 remote-as 400" 73 | c18 := "redistribute connected" 74 | node, err := goeapi.ConnectTo(host) 75 | if err != nil { 76 | log.Fatal(err) 77 | } 78 | fmt.Printf("Connected to %v\n", host) 79 | fmt.Printf("\n\n\nPre-Change state:\n\n\n") 80 | fmt.Println(node.Enable(cmds1)) 81 | fmt.Println(node.ConfigWithErr(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18)) 82 | fmt.Printf("\n\n\nPost-change state: \n\n\n") 83 | duration := time.Duration(15) * time.Second 84 | time.Sleep(duration) 85 | fmt.Println(node.Enable(cmds1)) 86 | fmt.Println(node.Enable(cmds2)) 87 | fmt.Printf("\n\n\n\n") 88 | 89 | } 90 | 91 | func deploy_ceos3() { 92 | 93 | host := "ceos3" 94 | cmds1 := []string{"show running-config"} 95 | cmds2 := []string{"show ip interface brief | json", "show ip ospf neighbor | json", "show ip bgp summary | json"} 96 | // Configuration commands 97 | c1 := "interface ethernet 1" 98 | c2 := "no switchport" 99 | c3 := "ip address 157.130.1.2/30" 100 | c4 := "no shutdown" 101 | c5 := "router bgp 300" 102 | c6 := "network 3.3.3.3 mask 255.255.255.255" 103 | c7 := "router-id 3.3.3.3" 104 | c8 := "neighbor 157.130.1.1 remote-as 100" 105 | c9 := "redistribute connected" 106 | node, err := goeapi.ConnectTo(host) 107 | if err != nil { 108 | log.Fatal(err) 109 | } 110 | fmt.Printf("Connected to %v\n", host) 111 | fmt.Printf("\n\n\nPre-Change state:\n\n\n") 112 | fmt.Println(node.Enable(cmds1)) 113 | fmt.Println(node.ConfigWithErr(c1, c2, c3, c4, c5, c6, c7, c8, c9)) 114 | fmt.Printf("\n\n\nPost-change state: \n\n\n") 115 | duration := time.Duration(15) * time.Second 116 | time.Sleep(duration) 117 | fmt.Println(node.Enable(cmds1)) 118 | fmt.Println(node.Enable(cmds2)) 119 | fmt.Printf("\n\n\n\n") 120 | } 121 | 122 | func deploy_ceos4() { 123 | 124 | host := "ceos4" 125 | cmds1 := []string{"show running-config"} 126 | cmds2 := []string{"show ip interface brief | json", "show ip ospf neighbor | json", "show ip bgp summary | json"} 127 | // Configuration commands 128 | c1 := "interface ethernet 1" 129 | c2 := "no switchport" 130 | c3 := "ip address 157.130.2.2/30" 131 | c4 := "no shutdown" 132 | c5 := "router bgp 400" 133 | c6 := "network 4.4.4.4 mask 255.255.255.255" 134 | c7 := "router-id 4.4.4.4" 135 | c8 := "neighbor 157.130.2.1 remote-as 100" 136 | c9 := "redistribute connected" 137 | node, err := goeapi.ConnectTo(host) 138 | if err != nil { 139 | log.Fatal(err) 140 | } 141 | fmt.Printf("Connected to %v\n", host) 142 | fmt.Printf("\n\n\nPre-Change state:\n\n\n") 143 | fmt.Println(node.Enable(cmds1)) 144 | fmt.Println(node.ConfigWithErr(c1, c2, c3, c4, c5, c6, c7, c8, c9)) 145 | fmt.Printf("\n\n\nPost-change state: \n\n\n") 146 | duration := time.Duration(15) * time.Second 147 | time.Sleep(duration) 148 | fmt.Println(node.Enable(cmds1)) 149 | fmt.Println(node.Enable(cmds2)) 150 | fmt.Printf("\n\n\n\n") 151 | } 152 | 153 | func main() { 154 | deploy_ceos1() 155 | deploy_ceos2() 156 | deploy_ceos3() 157 | deploy_ceos4() 158 | } 159 | -------------------------------------------------------------------------------- /arista/goeapi/show_commands/go,mod: -------------------------------------------------------------------------------- 1 | module show_commands 2 | 3 | go 1.22.2 4 | 5 | require github.com/aristanetworks/goeapi v1.0.0 6 | 7 | require ( 8 | github.com/mitchellh/mapstructure v1.5.0 // indirect 9 | github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect 10 | ) 11 | -------------------------------------------------------------------------------- /arista/goeapi/show_commands/go.sum: -------------------------------------------------------------------------------- 1 | github.com/aristanetworks/goeapi v1.0.0 h1:FjckkjOY32SkmKrqDyBqYu6hN7DaIJuxcii9LLdZqtQ= 2 | github.com/aristanetworks/goeapi v1.0.0/go.mod h1:DcgIvssM+qcRRVICDky/ecT/Gqpx40UQDTYY8Lu/iJ0= 3 | github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= 4 | github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 5 | github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks= 6 | github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw= 7 | -------------------------------------------------------------------------------- /arista/goeapi/show_commands/show_cmds.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/aristanetworks/goeapi" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | var HostList = []string{"ceos1", "ceos2", "ceos3", "ceos4", "ceos5", "ceos6"} 11 | 12 | func main() { 13 | // This will run the commands listed after the filename 14 | var s, sep string 15 | for i := 1; i < len(os.Args); i++ { 16 | s += sep + os.Args[i] 17 | sep = " " 18 | } 19 | cmds := strings.Split(s, ",") 20 | fmt.Println(cmds) 21 | for _, host := range HostList { 22 | node, err := goeapi.ConnectTo(host) 23 | if err != nil { 24 | fmt.Println(err) 25 | } 26 | fmt.Printf("Connected to %v\n", host) 27 | fmt.Println(node.Enable(cmds)) 28 | fmt.Printf("\n\n-------------------------------\n\n") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /arista/http_client/config_script.go: -------------------------------------------------------------------------------- 1 | // Configure the target device listed in the url 2 | // Entering the commands you want when you run the script. 3 | 4 | package main 5 | 6 | import ( 7 | "bytes" 8 | "crypto/tls" 9 | "encoding/json" 10 | "fmt" 11 | "io" 12 | "net/http" 13 | "os" 14 | "strings" 15 | ) 16 | 17 | type Parameters struct { 18 | Version int `json:"version"` 19 | Cmds []string `json:"cmds"` 20 | Format string `json:"format"` 21 | } 22 | 23 | type Request struct { 24 | Jsonrpc string `json:"jsonrpc"` 25 | Method string `json:"method"` 26 | Params Parameters `json:"params"` 27 | Id string `json:"id"` 28 | } 29 | 30 | func connect(url string, cmds []string, format string) *http.Response { 31 | p := Parameters{1, cmds, format} 32 | req := Request{"2.0", "runCmds", p, "1"} 33 | buf, err := json.Marshal(req) 34 | resp := new(http.Response) 35 | if err != nil { 36 | panic(err) 37 | } 38 | client := &http.Client{} 39 | if strings.HasPrefix(url, "https") { 40 | tr := &http.Transport{ 41 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 42 | } 43 | client = &http.Client{Transport: tr} 44 | } 45 | resp, err = client.Post(url, "application/json", bytes.NewReader(buf)) 46 | 47 | if err != nil { 48 | fmt.Println(err) 49 | panic(err) 50 | } 51 | return resp 52 | } 53 | 54 | func main() { 55 | var s, sep string 56 | for i := 1; i < len(os.Args); i++ { 57 | s += sep + os.Args[i] 58 | sep = " " 59 | } 60 | cmds := strings.Split(s, ",") 61 | fmt.Println(cmds) 62 | url := "https://arista:arista@192.168.1.117:8443/command-api/" 63 | resp := connect(url, cmds, "json") 64 | fmt.Println(resp) 65 | if resp.StatusCode == http.StatusOK { 66 | bodyBytes, err := io.ReadAll(resp.Body) 67 | if err != nil { 68 | fmt.Println(err) 69 | } 70 | bodyString := string(bodyBytes) 71 | fmt.Println(bodyString) 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /arista/http_client/config_script_output.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ go run config_script.go enable, configure, interface loopback70, ip address 70.70.70.70/32, description testAPI 2 | [enable configure interface loopback70 ip address 70.70.70.70/32 description testAPI] 3 | &{200 OK 200 HTTP/1.1 1 1 map[Cache-Control:[no-store no-cache must-revalidate max-age=0 pre-check=0 post-check=0] Connection:[keep-alive] Content-Type:[application/json] Date:[Wed, 05 Feb 2020 13:24:08 GMT] Pragma:[no-cache] Server:[nginx]] 0x140e230 -1 [chunked] false true map[] 0x1492200 0x150c000} 4 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ go run config_script.go enable, configure, interface loopback71, ip address 71.71.71.71/32, description testAPI 5 | [enable configure interface loopback71 ip address 71.71.71.71/32 description testAPI] 6 | &{200 OK 200 HTTP/1.1 1 1 map[Cache-Control:[no-store no-cache must-revalidate max-age=0 pre-check=0 post-check=0] Connection:[keep-alive] Content-Type:[application/json] Date:[Wed, 05 Feb 2020 13:24:31 GMT] Pragma:[no-cache] Server:[nginx]] 0x2088470 -1 [chunked] false true map[] 0x20ac200 0x20a6660} 7 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ 8 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ go run show_cmds.go show running-config 9 | [show running-config] 10 | ############################# 11 | Connected to ceos2 12 | [map[command:show running-config result:! Command: show running-config 13 | ! device: ceos2 (cEOSSim, EOS-4.20.5F) 14 | ! 15 | transceiver qsfp default-mode 4x10G 16 | ! 17 | hostname ceos2 18 | ip domain lookup source-interface Loopback1 19 | ip name-server vrf default 8.8.8.8 20 | ! 21 | spanning-tree mode mstp 22 | ! 23 | no aaa root 24 | ! 25 | username arista privilege 15 secret sha512 $6$TRQ598fliEOez7f0$Z83fBpOhtq/yNMPYLCDUi057bO2/Bj6upB/mKrYe6WXZbUG3q3iHOv/BPP/V/U15kRoMfdgsKUWzTz2UxDdBE1 26 | ! 27 | interface Ethernet1 28 | no switchport 29 | ip address 10.0.0.2/24 30 | ! 31 | interface Ethernet2 32 | ! 33 | interface Ethernet3 34 | ! 35 | interface Loopback1 36 | description router-id 37 | ip address 2.2.2.2/32 38 | ! 39 | interface Loopback2 40 | ! 41 | interface Loopback3 42 | ! 43 | interface Loopback70 44 | description testAPI 45 | ip address 70.70.70.70/32 46 | ! 47 | interface Loopback71 48 | description testAPI 49 | ip address 71.71.71.71/32 50 | ! 51 | ip access-list eapiExample 52 | 10 permit ip any any 53 | ! 54 | ip routing 55 | ! 56 | router ospf 1 57 | router-id 2.2.2.2 58 | network 2.2.2.2/32 area 0.0.0.0 59 | network 10.0.0.0/24 area 0.0.0.0 60 | max-lsa 12000 61 | ! 62 | management api http-commands 63 | no shutdown 64 | ! 65 | end]] 66 | ############################ 67 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ 68 | 69 | -------------------------------------------------------------------------------- /arista/http_client/config_script_output2.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ go run config_script.go enable, configure, interface loopback 70, description eapi_test, ip address 70.70.70.70/32 2 | [enable configure interface loopback 70 description eapi_test ip address 70.70.70.70/32] 3 | &{200 OK 200 HTTP/1.1 1 1 map[Cache-Control:[no-store no-cache must-revalidate max-age=0 pre-check=0 post-check=0] Connection:[keep-alive] Content-Type:[application/json] Date:[Wed, 05 Feb 2020 14:25:53 GMT] Pragma:[no-cache] Server:[nginx]] 0xd0c050 -1 [chunked] false true map[] 0xc92200 0xc126c0} 4 | {"jsonrpc": "2.0", "id": "1", "result": [{}, {}, {}, {}, {}]} 5 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ go run show_cmds.go show running-config 6 | [show running-config] 7 | ############################# 8 | Connected to ceos2 9 | [map[command:show running-config result:! Command: show running-config 10 | ! device: ceos2 (cEOSSim, EOS-4.20.5F) 11 | ! 12 | transceiver qsfp default-mode 4x10G 13 | ! 14 | hostname ceos2 15 | ip domain lookup source-interface Loopback1 16 | ip name-server vrf default 8.8.8.8 17 | ! 18 | spanning-tree mode mstp 19 | ! 20 | no aaa root 21 | ! 22 | username arista privilege 15 secret sha512 $6$TRQ598fliEOez7f0$Z83fBpOhtq/yNMPYLCDUi057bO2/Bj6upB/mKrYe6WXZbUG3q3iHOv/BPP/V/U15kRoMfdgsKUWzTz2UxDdBE1 23 | ! 24 | interface Ethernet1 25 | no switchport 26 | ip address 10.0.0.2/24 27 | ! 28 | interface Ethernet2 29 | ! 30 | interface Ethernet3 31 | ! 32 | interface Loopback1 33 | description router-id 34 | ip address 2.2.2.2/32 35 | ! 36 | interface Loopback2 37 | ! 38 | interface Loopback3 39 | ! 40 | interface Loopback70 41 | description eapi_test 42 | ip address 70.70.70.70/32 43 | ! 44 | ip access-list eapiExample 45 | 10 permit ip any any 46 | ! 47 | ip routing 48 | ! 49 | router ospf 1 50 | router-id 2.2.2.2 51 | network 2.2.2.2/32 area 0.0.0.0 52 | network 10.0.0.0/24 area 0.0.0.0 53 | max-lsa 12000 54 | ! 55 | management api http-commands 56 | no shutdown 57 | ! 58 | end]] 59 | ############################ 60 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ 61 | -------------------------------------------------------------------------------- /arista/http_client/config_script_v2.go: -------------------------------------------------------------------------------- 1 | // Using the device type struct you can configure mutiple device with unique configurations 2 | // This script is using ceos-lab platform and http Ports specify different hosts 3 | // (c) Todd Riemenschneider 2020 4 | 5 | package main 6 | 7 | import ( 8 | "bytes" 9 | "crypto/tls" 10 | "encoding/json" 11 | "fmt" 12 | "io" 13 | "net/http" 14 | "strings" 15 | ) 16 | 17 | type Parameters struct { 18 | Version int `json:"version"` 19 | Cmds []string `json:"cmds"` 20 | Format string `json:"format"` 21 | } 22 | 23 | type Request struct { 24 | Jsonrpc string `json:"jsonrpc"` 25 | Method string `json:"method"` 26 | Params Parameters `json:"params"` 27 | Id string `json:"id"` 28 | } 29 | 30 | type device struct { 31 | Host string 32 | Cmds []string 33 | } 34 | 35 | func connect(url string, cmds []string, format string) *http.Response { 36 | p := Parameters{1, cmds, format} 37 | req := Request{"2.0", "runCmds", p, "1"} 38 | buf, err := json.Marshal(req) 39 | resp := new(http.Response) 40 | if err != nil { 41 | panic(err) 42 | } 43 | client := &http.Client{} 44 | if strings.HasPrefix(url, "https") { 45 | tr := &http.Transport{ 46 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 47 | } 48 | client = &http.Client{Transport: tr} 49 | } 50 | resp, err = client.Post(url, "application/json", bytes.NewReader(buf)) 51 | if err != nil { 52 | fmt.Println(err) 53 | panic(err) 54 | } 55 | return resp 56 | } 57 | 58 | func main() { 59 | ceos1 := &device{ 60 | Host: "8443", 61 | Cmds: []string{"enable", "configure", "interface loopback3", "description ceos1 Lo3", "ip address 3.3.3.3/32", "router bgp 1", "network 3.3.3.3/32"}, 62 | } 63 | ceos2 := &device{ 64 | Host: "9443", 65 | Cmds: []string{"enable", "configure", "interface loopback4", "description ceos2 lo4", "ip address 4.4.4.4/32", "router bgp 2", "network 4.4.4.4/32"}, 66 | } 67 | ceos_lab := []*device{ceos1, ceos2} 68 | for _, ceos := range ceos_lab { 69 | url := "https://arista:arista@192.168.1.117:" + ceos.Host + "/command-api/" 70 | resp := connect(url, ceos.Cmds, "json") 71 | fmt.Println(resp) 72 | if resp.StatusCode == http.StatusOK { 73 | bodyBytes, err := io.ReadAll(resp.Body) 74 | if err != nil { 75 | fmt.Println(err) 76 | } 77 | bodyString := string(bodyBytes) 78 | fmt.Println(bodyString) 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /arista/http_client/config_script_v2_output.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ go run config_script_v2.go 2 | &{200 OK 200 HTTP/1.1 1 1 map[Cache-Control:[no-store no-cache must-revalidate max-age=0 pre-check=0 post-check=0] Connection:[keep-alive] Content-Type:[application/json] Date:[Mon, 11 May 2020 22:33:01 GMT] Pragma:[no-cache] Server:[nginx]] 0xcea050 -1 [chunked] false true map[] 0xc92200 0xc8c600} 3 | {"jsonrpc": "2.0", "id": "1", "result": [{}, {}, {}, {}, {}, {}, {}]} 4 | &{200 OK 200 HTTP/1.1 1 1 map[Cache-Control:[no-store no-cache must-revalidate max-age=0 pre-check=0 post-check=0] Connection:[keep-alive] Content-Type:[application/json] Date:[Mon, 11 May 2020 22:33:01 GMT] Pragma:[no-cache] Server:[nginx]] 0xcea3c0 -1 [chunked] false true map[] 0xd2c080 0xd20120} 5 | {"jsonrpc": "2.0", "id": "1", "result": [{}, {}, {}, {}, {}, {}, {}]} 6 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ 7 | 8 | 9 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ go run show_cmds.go show running-config 10 | [show running-config] 11 | ############################# 12 | Connected to ceos1 13 | [map[command:show running-config result:! Command: show running-config 14 | ! device: ceos1 (cEOSLab, EOS-4.23.3M) 15 | ! 16 | transceiver qsfp default-mode 4x10G 17 | ! 18 | agent Bfd shutdown 19 | agent PowerManager shutdown 20 | agent LedPolicy shutdown 21 | agent Thermostat shutdown 22 | agent PowerFuse shutdown 23 | agent StandbyCpld shutdown 24 | agent LicenseManager shutdown 25 | ! 26 | hostname ceos1 27 | ! 28 | spanning-tree mode mstp 29 | ! 30 | no aaa root 31 | ! 32 | username arista privilege 15 secret sha512 $6$7FWNPnRoPkXJgo2H$ssT3J3oBdwk/pYcaAKhwK08ogkXU7.oKjgmhM6vMZ2/VcGe.NuiB5bIzonFi4SJVA4ismhPwidUsoeFvvHezS1 33 | ! 34 | interface Ethernet1 35 | no switchport 36 | ip address 10.0.0.1/24 37 | ! 38 | interface Ethernet2 39 | ! 40 | interface Loopback1 41 | description router-id 42 | ip address 1.1.1.1/32 43 | ! 44 | interface Loopback3 45 | description ceos1 Lo3 46 | ip address 3.3.3.3/32 47 | ! 48 | ip routing 49 | ! 50 | router bgp 1 51 | neighbor 10.0.0.2 remote-as 2 52 | neighbor 10.0.0.2 maximum-routes 12000 53 | network 1.1.1.1/32 54 | network 3.3.3.3/32 55 | ! 56 | management api http-commands 57 | no shutdown 58 | ! 59 | end]] 60 | ############################ 61 | ############################# 62 | Connected to ceos2 63 | [map[command:show running-config result:! Command: show running-config 64 | ! device: ceos2 (cEOSLab, EOS-4.23.3M) 65 | ! 66 | transceiver qsfp default-mode 4x10G 67 | ! 68 | agent Bfd shutdown 69 | agent PowerManager shutdown 70 | agent LedPolicy shutdown 71 | agent Thermostat shutdown 72 | agent PowerFuse shutdown 73 | agent StandbyCpld shutdown 74 | agent LicenseManager shutdown 75 | ! 76 | hostname ceos2 77 | ! 78 | spanning-tree mode mstp 79 | ! 80 | no aaa root 81 | ! 82 | username arista privilege 15 secret sha512 $6$x60Ym99BaPBBW3Or$YxSI7vh3F4USDtdjdrE1d.CALbvjuTv9abWPX4TM4hrF41tBxiI.HNayhTP0HUTaI5Iv0ZYCOKl/dx7564o0b/ 83 | ! 84 | interface Ethernet1 85 | no switchport 86 | ip address 10.0.0.2/24 87 | ! 88 | interface Ethernet2 89 | ! 90 | interface Loopback1 91 | description router-id 92 | ip address 2.2.2.2/32 93 | ! 94 | interface Loopback4 95 | description ceos2 lo4 96 | ip address 4.4.4.4/32 97 | ! 98 | ip routing 99 | ! 100 | router bgp 2 101 | neighbor 10.0.0.1 remote-as 1 102 | neighbor 10.0.0.1 maximum-routes 12000 103 | network 2.2.2.2/32 104 | network 4.4.4.4/32 105 | ! 106 | management api http-commands 107 | no shutdown 108 | ! 109 | end]] 110 | ############################ 111 | pi@RaspPi4:~/Coding/Go_folder/netOps/goeapi_folder $ 112 | -------------------------------------------------------------------------------- /arista/lab_setup/ceoslab_6_devices Diagram.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/twr14152/Go_Network_Scripts/251c8d5d78ef541162dc5940d33a565cf4772fa5/arista/lab_setup/ceoslab_6_devices Diagram.drawio.png -------------------------------------------------------------------------------- /arista/ssh_client/README.md: -------------------------------------------------------------------------------- 1 | This was more of a can i do it script. The default authentication method used for arista is keyboard interactive. This is different from Cisco by default. 2 | This script is more of a screen scraping cli script that could be used to connect to multiple device and issue various commands (configs or show commands). 3 | Good to use in a lab. 4 | ``` 5 | twr14152@DESKTOP-S55FNN9:~/code_folder/go_folder/misc/go_net_scripts/ssh_client$ go run main.go 6 | Number of hosts: 2 7 | 8 | Enter host and ssh port being used. (Ex. x.x.x.x:22 or hostname:22) 9 | 10 | 11 | Enter host: ceos1:22 12 | 13 | cmds: enable, config, interface loopback 9, description testing_script, sh run int loopback 9, show ip int brief, no interface loopback 9, show ip int brief 14 | 15 | Enter host: ceos2:22 16 | 17 | cmds: enable, show version, show ip arp, show ip int brief 18 | 19 | ++++++++++++++++++++++++++++++++ 20 | Connected to: ceos1:22 21 | ++++++++++++++++++++++++++++++++ 22 | Pagination disabled. 23 | interface Loopback9 24 | description testing_script 25 | Address 26 | Interface IP Address Status Protocol MTU Owner 27 | --------------- ------------------ ----------- ------------- ---------- ------- 28 | Loopback0 1.1.1.1/32 up up 65535 29 | Loopback9 unassigned up up 65535 30 | Management0 172.17.0.2/16 up up 1500 31 | 32 | Address 33 | Interface IP Address Status Protocol MTU Owner 34 | --------------- ------------------ ----------- ------------- ---------- ------- 35 | Loopback0 1.1.1.1/32 up up 65535 36 | Management0 172.17.0.2/16 up up 1500 37 | 38 | ++++++++++++++++++++++++++++++++ 39 | Connected to: ceos2:22 40 | ++++++++++++++++++++++++++++++++ 41 | Pagination disabled. 42 | Arista cEOSLab 43 | Hardware version: 44 | Serial number: 45 | Hardware MAC address: 0242.ac97.38c5 46 | System MAC address: 0242.ac97.38c5 47 | 48 | Software image version: 4.30.5M-35156751.4305M (engineering build) 49 | Architecture: x86_64 50 | Internal build version: 4.30.5M-35156751.4305M 51 | Internal build ID: 29383dc6-2c4f-445b-8162-1209cd1b57df 52 | Image format version: 1.0 53 | Image optimization: None 54 | 55 | cEOS tools version: (unknown) 56 | Kernel version: 5.15.146.1-microsoft-standard-WSL2 57 | 58 | Uptime: 2 days, 7 hours and 37 minutes 59 | Total memory: 8108944 kB 60 | Free memory: 1780132 kB 61 | 62 | Address Age (sec) Hardware Addr Interface 63 | 172.17.0.1 0:00:00 0242.da6b.0d0e Management0 64 | Address 65 | Interface IP Address Status Protocol MTU Owner 66 | --------------- ------------------ ----------- ------------- ---------- ------- 67 | Loopback0 2.2.2.2/32 up up 65535 68 | Loopback69 unassigned up up 65535 69 | Management0 172.17.0.3/16 up up 1500 70 | 71 | twr14152@DESKTOP-S55FNN9:~/code_folder/go_folder/misc/go_net_scripts/ssh_client$ 72 | 73 | ``` 74 | -------------------------------------------------------------------------------- /arista/ssh_client/go.mod: -------------------------------------------------------------------------------- 1 | module ssh_client 2 | 3 | go 1.22.2 4 | 5 | require golang.org/x/crypto v0.22.0 6 | 7 | require golang.org/x/sys v0.19.0 // indirect 8 | 9 | -------------------------------------------------------------------------------- /arista/ssh_client/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= 2 | golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= 3 | golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= 4 | golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 5 | golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= 6 | golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= 7 | -------------------------------------------------------------------------------- /arista/ssh_client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "log" 7 | "os" 8 | "strings" 9 | "golang.org/x/crypto/ssh" 10 | ) 11 | 12 | func commands() map[string][]string { 13 | var count int 14 | var host string 15 | fmt.Print("Number of hosts: ") 16 | fmt.Scanf("%d", &count) 17 | hostCmds := make(map[string][]string) 18 | fmt.Printf("\nEnter host and ssh port being used. (Ex. x.x.x.x:22 or hostname:22)\n\n\n") 19 | for i := 1; i <= count; i++ { 20 | fmt.Print("Enter host: ") 21 | fmt.Scanf("%s", &host) 22 | fmt.Println() 23 | reader := bufio.NewReader(os.Stdin) 24 | fmt.Print("cmds: ") 25 | cmds, err := reader.ReadString('\n') 26 | if err != nil { 27 | log.Fatal("You screwed something up: ", err) 28 | } 29 | s := strings.Split(cmds, ",") 30 | fmt.Println() 31 | hostCmds[host] = s 32 | } 33 | return hostCmds 34 | } 35 | 36 | func main() { 37 | user := "arista" 38 | pass := "arista" 39 | hostData := commands() 40 | 41 | interactiveAuth := ssh.KeyboardInteractive( 42 | func(user, instruction string, questions []string, echos []bool) ([]string, error) { 43 | answers := make([]string, len(questions)) 44 | for i := range answers { 45 | answers[i] = pass 46 | } 47 | 48 | return answers, nil 49 | }, 50 | ) 51 | 52 | for host, commands := range hostData { 53 | config := &ssh.ClientConfig{ 54 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 55 | User: user, 56 | Auth: []ssh.AuthMethod{interactiveAuth}, 57 | } 58 | fmt.Println("++++++++++++++++++++++++++++++++") 59 | fmt.Println("Connected to: ", host) 60 | fmt.Println("++++++++++++++++++++++++++++++++") 61 | conn, err := ssh.Dial("tcp", host, config) 62 | if err != nil { 63 | log.Fatal("Failed to dial: ", err) 64 | } 65 | defer conn.Close() 66 | sess, err := conn.NewSession() 67 | if err != nil { 68 | log.Fatal("Failed to create session: ", err) 69 | } 70 | defer sess.Close() 71 | stdin, err := sess.StdinPipe() 72 | if err != nil { 73 | log.Fatal("Failed to connect to remote devices stdin: ", err) 74 | } 75 | sess.Stdout = os.Stdout 76 | sess.Stderr = os.Stderr 77 | sess.Shell() 78 | fmt.Fprintf(stdin, "term len 0\n") 79 | for _, v := range commands { 80 | fmt.Fprintf(stdin, "%s\n", v) 81 | } 82 | stdin.Close() 83 | sess.Wait() 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /http_client/PostCmds.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | var config = []byte(`{ 4 | "ietf-interfaces:interface": { 5 | "name": "Loopback69", 6 | "description": "Testing Golang RestConf", 7 | "type": "iana-if-type:softwareLoopback", 8 | "enabled": true, 9 | "ietf-ip:ipv4": { 10 | "address": [ 11 | { 12 | "ip": "69.69.69.1", 13 | "netmask": "255.255.255.255" 14 | } 15 | ] 16 | } 17 | } 18 | }`) 19 | -------------------------------------------------------------------------------- /http_client/host_file001.txt: -------------------------------------------------------------------------------- 1 | ios-xe-mgmt-latest.cisco.com:9443 2 | ios-xe-mgmt-latest.cisco.com:9443 3 | ios-xe-mgmt-latest.cisco.com:9443 4 | -------------------------------------------------------------------------------- /http_client/host_file002.txt: -------------------------------------------------------------------------------- 1 | ios-xe-mgmt-latest.cisco.com:9443 2 | ios-xe-mgmt.cisco.com:9443 3 | -------------------------------------------------------------------------------- /http_client/httpGet_v1.go: -------------------------------------------------------------------------------- 1 | // This script will use https to pull router info 2 | // https://host:port/restconf/data/etc:etc will determine what info is gathered 3 | // (c) 2019 Todd Riemenschneider 4 | 5 | package main 6 | 7 | import ( 8 | "crypto/tls" 9 | "fmt" 10 | "io" 11 | "net/http" 12 | ) 13 | 14 | func main() { 15 | certInfo := &http.Transport{ 16 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 17 | } 18 | client := &http.Client{Transport: certInfo} 19 | url := "https://sandbox-iosxe-latest-1.cisco.com/restconf/data/Cisco-IOS-XE-native:native?content=config&depth=65535" 20 | 21 | req, _ := http.NewRequest("GET", url, nil) 22 | req.Header.Add("Content-Type", "application/yang-data+json") 23 | req.Header.Add("Accept", "application/yang-data+json") 24 | req.SetBasicAuth("developer", "C1sco12345") 25 | 26 | res, _ := client.Do(req) 27 | defer res.Body.Close() 28 | body, _ := io.ReadAll(res.Body) 29 | 30 | fmt.Println(res) 31 | fmt.Println(string(body)) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /http_client/httpGet_v2.go: -------------------------------------------------------------------------------- 1 | // This script will use restconf to pull router interface info off the devices in the host_file001.txt 2 | // (c) 2019 Todd Riemenschneider 3 | 4 | package main 5 | 6 | import ( 7 | "bufio" 8 | "crypto/tls" 9 | "fmt" 10 | "io/ioutil" 11 | "log" 12 | "net/http" 13 | "os" 14 | ) 15 | 16 | var hostList []string 17 | 18 | func main() { 19 | hf, _ := os.Open("host_file001.txt") 20 | scanner := bufio.NewScanner(hf) 21 | scanner.Split(bufio.ScanLines) 22 | for scanner.Scan() { 23 | hostList = append(hostList, scanner.Text()) 24 | } 25 | certInfo := &http.Transport{ 26 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 27 | } 28 | UN := "developer" 29 | PW := "C1sco12345" 30 | fmt.Println(hostList) 31 | client := &http.Client{Transport: certInfo} 32 | 33 | for i, host := range hostList { 34 | fmt.Println("connected to host: ", i) 35 | //url := ("https://"+host+"/restconf/data/ietf-interfaces:interfaces/interface=Loopback71") 36 | url := ("https://" + host + "/restconf/data/ietf-interfaces:interfaces") 37 | req, err := http.NewRequest("GET", url, nil) 38 | req.SetBasicAuth(UN, PW) 39 | req.Header.Add("Content-Type", "application/yang-data+json") 40 | req.Header.Add("Accept", "application/yang-data+json") 41 | resp, err := client.Do(req) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | deviceOutput, err := ioutil.ReadAll(resp.Body) 46 | fmt.Println(string(deviceOutput)) 47 | } 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /http_client/httpGet_v2_output.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/http_folder $ go run httpGet_v2.go 2 | [ios-xe-mgmt-latest.cisco.com:9443 ios-xe-mgmt.cisco.com:9443] 3 | connected to host: 0 4 | { 5 | "ietf-interfaces:interfaces": { 6 | "interface": [ 7 | { 8 | "name": "GigabitEthernet1", 9 | "description": "MANAGEMENT INTERFACE - DON'T TOUCH ME", 10 | "type": "iana-if-type:ethernetCsmacd", 11 | "enabled": true, 12 | "ietf-ip:ipv4": { 13 | "address": [ 14 | { 15 | "ip": "10.10.20.48", 16 | "netmask": "255.255.255.0" 17 | } 18 | ] 19 | }, 20 | "ietf-ip:ipv6": { 21 | } 22 | }, 23 | { 24 | "name": "GigabitEthernet2", 25 | "description": "Network Interface", 26 | "type": "iana-if-type:ethernetCsmacd", 27 | "enabled": false, 28 | "ietf-ip:ipv4": { 29 | }, 30 | "ietf-ip:ipv6": { 31 | } 32 | }, 33 | { 34 | "name": "GigabitEthernet3", 35 | "description": "Network Interface", 36 | "type": "iana-if-type:ethernetCsmacd", 37 | "enabled": false, 38 | "ietf-ip:ipv4": { 39 | }, 40 | "ietf-ip:ipv6": { 41 | } 42 | }, 43 | { 44 | "name": "Loopback74", 45 | "description": "Testing Golang RestConf", 46 | "type": "iana-if-type:softwareLoopback", 47 | "enabled": true, 48 | "ietf-ip:ipv4": { 49 | "address": [ 50 | { 51 | "ip": "74.74.74.1", 52 | "netmask": "255.255.255.255" 53 | } 54 | ] 55 | }, 56 | "ietf-ip:ipv6": { 57 | } 58 | } 59 | ] 60 | } 61 | } 62 | 63 | connected to host: 1 64 | { 65 | "ietf-interfaces:interfaces": { 66 | "interface": [ 67 | { 68 | "name": "GigabitEthernet1", 69 | "description": "MANAGEMENT INTERFACE - DON'T TOUCH ME", 70 | "type": "iana-if-type:ethernetCsmacd", 71 | "enabled": true, 72 | "ietf-ip:ipv4": { 73 | "address": [ 74 | { 75 | "ip": "10.10.20.48", 76 | "netmask": "255.255.255.0" 77 | } 78 | ] 79 | }, 80 | "ietf-ip:ipv6": { 81 | } 82 | }, 83 | { 84 | "name": "GigabitEthernet2", 85 | "description": "Gruesse an die Deutschsprachigen", 86 | "type": "iana-if-type:ethernetCsmacd", 87 | "enabled": true, 88 | "ietf-ip:ipv4": { 89 | "address": [ 90 | { 91 | "ip": "10.255.255.1", 92 | "netmask": "255.255.255.0" 93 | } 94 | ] 95 | }, 96 | "ietf-ip:ipv6": { 97 | } 98 | }, 99 | { 100 | "name": "GigabitEthernet3", 101 | "description": "Network Interface", 102 | "type": "iana-if-type:ethernetCsmacd", 103 | "enabled": true, 104 | "ietf-ip:ipv4": { 105 | "address": [ 106 | { 107 | "ip": "30.0.0.1", 108 | "netmask": "255.255.255.0" 109 | } 110 | ] 111 | }, 112 | "ietf-ip:ipv6": { 113 | } 114 | }, 115 | { 116 | "name": "GigabitEthernet3.1", 117 | "description": "testSerge", 118 | "type": "iana-if-type:ethernetCsmacd", 119 | "enabled": true, 120 | "ietf-ip:ipv4": { 121 | "address": [ 122 | { 123 | "ip": "101.0.0.1", 124 | "netmask": "255.255.255.0" 125 | }, 126 | { 127 | "ip": "101.0.1.1", 128 | "netmask": "255.255.255.0" 129 | }, 130 | { 131 | "ip": "101.0.2.1", 132 | "netmask": "255.255.255.0" 133 | } 134 | ] 135 | }, 136 | "ietf-ip:ipv6": { 137 | } 138 | }, 139 | { 140 | "name": "Loopback1", 141 | "description": "Changed by me", 142 | "type": "iana-if-type:softwareLoopback", 143 | "enabled": true, 144 | "ietf-ip:ipv4": { 145 | "address": [ 146 | { 147 | "ip": "1.2.3.4", 148 | "netmask": "255.255.255.0" 149 | } 150 | ] 151 | }, 152 | "ietf-ip:ipv6": { 153 | } 154 | }, 155 | { 156 | "name": "Loopback101", 157 | "description": "Pod Number 1410", 158 | "type": "iana-if-type:softwareLoopback", 159 | "enabled": true, 160 | "ietf-ip:ipv4": { 161 | "address": [ 162 | { 163 | "ip": "10.10.10.1", 164 | "netmask": "255.255.255.0" 165 | } 166 | ] 167 | }, 168 | "ietf-ip:ipv6": { 169 | } 170 | }, 171 | { 172 | "name": "Loopback200", 173 | "description": "Configured by RESTCONF200", 174 | "type": "iana-if-type:softwareLoopback", 175 | "enabled": true, 176 | "ietf-ip:ipv4": { 177 | "address": [ 178 | { 179 | "ip": "172.16.100.1", 180 | "netmask": "255.255.255.0" 181 | } 182 | ] 183 | }, 184 | "ietf-ip:ipv6": { 185 | } 186 | } 187 | ] 188 | } 189 | } 190 | 191 | pi@RaspPi4:~/Coding/Go_folder/netOps/http_folder $ 192 | 193 | 194 | 195 | Previous version of script 196 | 197 | pi@raspberrypi:~/Code_folder/go_folder/netOps/http_client $ go run httpGet_v2.go 198 | [ios-xe-mgmt-latest.cisco.com:9443 ios-xe-mgmt-latest.cisco.com:9443 ios-xe-mgmt-latest.cisco.com:9443] 199 | connected to host: 0 200 | 201 | 202 | Loopback71 203 | testing go_ssh 204 | ianaift:softwareLoopback 205 | true 206 | 207 | 208 | 209 | 210 | 211 | 212 | connected to host: 1 213 | 214 | 215 | Loopback71 216 | testing go_ssh 217 | ianaift:softwareLoopback 218 | true 219 | 220 | 221 | 222 | 223 | 224 | 225 | connected to host: 2 226 | 227 | 228 | Loopback71 229 | testing go_ssh 230 | ianaift:softwareLoopback 231 | true 232 | 233 | 234 | 235 | 236 | 237 | 238 | pi@raspberrypi:~/Code_folder/go_folder/netOps/http_client $ 239 | -------------------------------------------------------------------------------- /http_client/httpPost_v1.go: -------------------------------------------------------------------------------- 1 | // Connecting to Restconf API on Cisco router and configuring an interface 2 | // (c) 2019 Todd Riemenschneider 3 | 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | "net/http" 9 | "io/ioutil" 10 | "crypto/tls" 11 | "bytes" 12 | ) 13 | 14 | func main() { 15 | certInfo := &http.Transport{ 16 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 17 | } 18 | 19 | config := []byte(`{ 20 | "ietf-interfaces:interface": { 21 | "name": "Loopback74", 22 | "description": "Testing Golang RestConf", 23 | "type": "iana-if-type:softwareLoopback", 24 | "enabled": true, 25 | "ietf-ip:ipv4": { 26 | "address": [ 27 | { 28 | "ip": "74.74.74.1", 29 | "netmask": "255.255.255.255" 30 | } 31 | ] 32 | } 33 | } 34 | }`) 35 | 36 | fmt.Println("config in bytes then in str fmt:\n ", config,"\n", string(config)) 37 | client := &http.Client{Transport: certInfo} 38 | url := "https://ios-xe-mgmt-latest.cisco.com:9443/restconf/data/ietf-interfaces:interfaces" 39 | 40 | req, _ := http.NewRequest("POST", url, bytes.NewBuffer(config)) 41 | req.SetBasicAuth("developer", "C1sco12345") 42 | req.Header.Add("Content-Type", "application/yang-data+json") 43 | req.Header.Add("Accept", "application/yang-data+json") 44 | 45 | res, _ := client.Do(req) 46 | defer res.Body.Close() 47 | body, _ := ioutil.ReadAll(res.Body) 48 | fmt.Println("Device Response:\n ",(res)) 49 | fmt.Println("This is the output of body: ", string(body)) 50 | } 51 | -------------------------------------------------------------------------------- /http_client/httpPost_v1_output.txt: -------------------------------------------------------------------------------- 1 | pi@raspberrypi:~/Code_folder/go_folder/netOps/http_client $ go run httpGet_v2.go 2 | [ios-xe-mgmt-latest.cisco.com:9443 ios-xe-mgmt-latest.cisco.com:9443 ios-xe-mgmt-latest.cisco.com:9443] 3 | connected to host: 0 4 | 5 | connected to host: 1 6 | 7 | connected to host: 2 8 | 9 | pi@raspberrypi:~/Code_folder/go_folder/netOps/http_client $ go run httpPost_v1.go 10 | &{201 Created 201 HTTP/1.1 1 1 map[Cache-Control:[private, no-cache, must-revalidate, proxy-revalidate] Connection:[keep-alive] Content-Length:[0] Content-Type:[text/html] Date:[Sat, 02 Nov 2019 18:23:57 GMT] Etag:[1572-719037-469264] Last-Modified:[Sat, 02 Nov 2019 18:23:57 GMT] Location:[https://ios-xe-mgmt-latest.cisco.com/restconf/data/ietf-interfaces:interfaces/interface=Loopback72] Pragma:[no-cache] Server:[nginx]] {} 0 [] false false map[] 0x1496180 0x151a0c0} 11 | 12 | pi@raspberrypi:~/Code_folder/go_folder/netOps/http_client $ go run httpGet_v2.go 13 | [ios-xe-mgmt-latest.cisco.com:9443 ios-xe-mgmt-latest.cisco.com:9443 ios-xe-mgmt-latest.cisco.com:9443] 14 | connected to host: 0 15 | 16 | 17 | Loopback72 18 | Testing Golang RestConf 19 | ianaift:softwareLoopback 20 | true 21 | 22 |
23 | 72.72.72.1 24 | 255.255.255.255 25 |
26 |
27 | 28 | 29 |
30 | 31 | connected to host: 1 32 | 33 | 34 | Loopback72 35 | Testing Golang RestConf 36 | ianaift:softwareLoopback 37 | true 38 | 39 |
40 | 72.72.72.1 41 | 255.255.255.255 42 |
43 |
44 | 45 | 46 |
47 | 48 | connected to host: 2 49 | 50 | 51 | Loopback72 52 | Testing Golang RestConf 53 | ianaift:softwareLoopback 54 | true 55 | 56 |
57 | 72.72.72.1 58 | 255.255.255.255 59 |
60 |
61 | 62 | 63 |
64 | 65 | pi@raspberrypi:~/Code_folder/go_folder/netOps/http_client $ 66 | -------------------------------------------------------------------------------- /http_client/httpPost_v2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "io/ioutil" 7 | "crypto/tls" 8 | "bytes" 9 | "bufio" 10 | "os" 11 | ) 12 | 13 | 14 | var hostList []string 15 | 16 | func main() { 17 | hf, _ := os.Open("host_file002.txt") 18 | scanner := bufio.NewScanner(hf) 19 | scanner.Split(bufio.ScanLines) 20 | for scanner.Scan() { 21 | hostList = append(hostList, scanner.Text()) 22 | } 23 | certInfo := &http.Transport{ 24 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 25 | } 26 | client := &http.Client{Transport: certInfo} 27 | for _, host := range hostList { 28 | fmt.Println("The config being loaded:\n", /*config, "\n",*/ string(config)) 29 | url := "https://"+host+"/restconf/data/ietf-interfaces:interfaces" 30 | 31 | // the config variable comes from PostCmds.go file 32 | req, _ := http.NewRequest("POST", url, bytes.NewBuffer(config)) 33 | req.SetBasicAuth("developer", "C1sco12345") 34 | req.Header.Add("Content-Type", "application/yang-data+json") 35 | req.Header.Add("Accept", "application/yang-data+json") 36 | 37 | res, _ := client.Do(req) 38 | fmt.Println("Connecting to host: ", host) 39 | defer res.Body.Close() 40 | body, _ := ioutil.ReadAll(res.Body) 41 | // This will print either created (success 201) or conflict (failure 409) 42 | fmt.Println("Device Response:\n ",(res)) 43 | fmt.Println("This is the output of body: ", string(body)) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /http_client/httpPost_v2_output.txt: -------------------------------------------------------------------------------- 1 | go run httpPost_v2.go PostCmds.go | tee httpPost_v2_output.txt 2 | The config being loaded: 3 | { 4 | "ietf-interfaces:interface": { 5 | "name": "Loopback69", 6 | "description": "Testing Golang RestConf", 7 | "type": "iana-if-type:softwareLoopback", 8 | "enabled": true, 9 | "ietf-ip:ipv4": { 10 | "address": [ 11 | { 12 | "ip": "69.69.69.1", 13 | "netmask": "255.255.255.255" 14 | } 15 | ] 16 | } 17 | } 18 | } 19 | Connecting to host: ios-xe-mgmt-latest.cisco.com:9443 20 | Device Response: 21 | &{201 Created 201 HTTP/1.1 1 1 map[Cache-Control:[private, no-cache, must-revalidate, proxy-revalidate] Connection:[keep-alive] Content-Length:[0] Content-Type:[text/html] Date:[Mon, 04 Nov 2019 22:26:56 GMT] Etag:[1572-906416-412968] Last-Modified:[Mon, 04 Nov 2019 22:26:56 GMT] Location:[https://ios-xe-mgmt-latest.cisco.com/restconf/data/ietf-interfaces:interfaces/interface=Loopback69] Pragma:[no-cache] Server:[nginx]] {} 0 [] false false map[] 0x1cac180 0x1d380c0} 22 | This is the output of body: 23 | The config being loaded: 24 | { 25 | "ietf-interfaces:interface": { 26 | "name": "Loopback69", 27 | "description": "Testing Golang RestConf", 28 | "type": "iana-if-type:softwareLoopback", 29 | "enabled": true, 30 | "ietf-ip:ipv4": { 31 | "address": [ 32 | { 33 | "ip": "69.69.69.1", 34 | "netmask": "255.255.255.255" 35 | } 36 | ] 37 | } 38 | } 39 | } 40 | Connecting to host: ios-xe-mgmt.cisco.com:9443 41 | Device Response: 42 | &{201 Created 201 HTTP/1.1 1 1 map[Cache-Control:[private, no-cache, must-revalidate, proxy-revalidate] Connection:[keep-alive] Content-Length:[0] Content-Type:[text/html] Date:[Mon, 04 Nov 2019 22:28:28 GMT] Etag:[1572-906508-73187] Last-Modified:[Mon, 04 Nov 2019 22:28:28 GMT] Location:[https://ios-xe-mgmt.cisco.com/restconf/data/ietf-interfaces:interfaces/interface=Loopback69] Pragma:[no-cache] Server:[nginx]] {} 0 [] false false map[] 0x1d8e100 0x1ca4720} 43 | This is the output of body: 44 | pi@raspberrypi:~/Code_folder/go_folder/netOps/http_client $ 45 | -------------------------------------------------------------------------------- /http_client/httpPost_v3.go: -------------------------------------------------------------------------------- 1 | // Connecting to Restconf API on Cisco router and configuring an interface and enabling ospf for that interface 2 | // (c) 2020 Todd Riemenschneider 3 | 4 | package main 5 | 6 | import ( 7 | "bytes" 8 | "crypto/tls" 9 | "fmt" 10 | "io/ioutil" 11 | "net/http" 12 | ) 13 | 14 | func main() { 15 | certInfo := &http.Transport{ 16 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 17 | } 18 | 19 | if_config := []byte(`{ 20 | "ietf-interfaces:interface": { 21 | "name": "Loopback74", 22 | "description": "Testing Golang RestConf", 23 | "type": "iana-if-type:softwareLoopback", 24 | "enabled": true, 25 | "ietf-ip:ipv4": { 26 | "address": [ 27 | { 28 | "ip": "74.74.74.1", 29 | "netmask": "255.255.255.255" 30 | } 31 | ] 32 | } 33 | } 34 | }`) 35 | 36 | rting_config := []byte(` 37 | { 38 | "Cisco-IOS-XE-ospf:ospf": [ 39 | { 40 | "id": 74, 41 | "router-id": "74.74.74.1", 42 | "network": [ 43 | { 44 | "ip": "74.74.74.1", 45 | "mask": "0.0.0.0", 46 | "area": 74 47 | } 48 | ] 49 | } 50 | ] 51 | } 52 | `) 53 | 54 | fmt.Println("config being applied:\n ", string(if_config)) 55 | client := &http.Client{Transport: certInfo} 56 | url_intf := "https://ios-xe-mgmt-latest.cisco.com:9443/restconf/data/ietf-interfaces:interfaces" 57 | req, _ := http.NewRequest("POST", url_intf, bytes.NewBuffer(if_config)) 58 | req.SetBasicAuth("developer", "C1sco12345") 59 | req.Header.Add("Content-Type", "application/yang-data+json") 60 | req.Header.Add("Accept", "application/yang-data+json") 61 | 62 | res, _ := client.Do(req) 63 | defer res.Body.Close() 64 | body, _ := ioutil.ReadAll(res.Body) 65 | fmt.Println("Device Response:\n ", (res)) 66 | fmt.Println("This is the output of body: ", string(body)) 67 | 68 | fmt.Println("config being applied: \n", string(rting_config)) 69 | url_rting := ("https://ios-xe-mgmt-latest.cisco.com:9443/restconf/data/Cisco-IOS-XE-native:native/router/") 70 | req1, _ := http.NewRequest("POST", url_rting, bytes.NewBuffer(rting_config)) 71 | req1.SetBasicAuth("developer", "C1sco12345") 72 | req1.Header.Add("Content-Type", "application/yang-data+json") 73 | req1.Header.Add("Accept", "application/yang-data+json") 74 | 75 | res1, _ := client.Do(req1) 76 | defer res1.Body.Close() 77 | body1, _ := ioutil.ReadAll(res1.Body) 78 | fmt.Println("Device Response:\n ", (res1)) 79 | fmt.Println("This is the output of body: ", string(body1)) 80 | 81 | } 82 | -------------------------------------------------------------------------------- /misc_folder/cli_args.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | func main() { 10 | cmdstring := strings.Join(os.Args[1:], " ") 11 | fmt.Println(cmdstring) 12 | cmdslice := strings.Split(cmdstring, ",") 13 | fmt.Println(cmdslice) 14 | } 15 | -------------------------------------------------------------------------------- /misc_folder/methodsTest.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type Switch struct { 6 | Name string 7 | Interface string 8 | IntDescr string 9 | Ip string 10 | RoutingProt string 11 | Network string 12 | } 13 | 14 | // Testing Method 15 | func (sw *Switch) confInfo() { 16 | fmt.Println("hostname", sw.Name) 17 | fmt.Println(" interface", sw.Interface) 18 | fmt.Println(sw.IntDescr) 19 | fmt.Println("", sw.Ip, "255.255.255.255") 20 | fmt.Println("router", sw.RoutingProt) 21 | fmt.Println(" network", sw.Network, "255.255.255.0") 22 | } 23 | 24 | func main() { 25 | core1 := Switch{Name: "CORE_SW1", Interface: "loopback0", IntDescr: " management interface CORE_SW1", Ip: "65.90.100.1", RoutingProt: "bgp 65001", Network: "10.0.0.0"} 26 | core2 := Switch{Name: "CORE_SW2", Interface: "loopback0", IntDescr: " management interface CORE_SW2", Ip: "65.90.100.2", RoutingProt: "bgp 65001", Network: "10.0.0.0"} 27 | // Using positional args for var assignment in Switch struct 28 | core3 := Switch{"CORE_SW3", "Loopback1", " Test Loopback on CORE_SW3", "10.10.10.2", "ospf 100", "10.10.10.0"} 29 | 30 | core1.confInfo() 31 | fmt.Println("+++++++++++++++++++") 32 | core2.confInfo() 33 | fmt.Println("+++++++++++++++++++") 34 | core3.confInfo() 35 | } 36 | -------------------------------------------------------------------------------- /misc_folder/methodsTest_output.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps $ go run methodsTest.go 2 | hostname CORE_SW1 3 | interface loopback0 4 | management interface CORE_SW1 5 | 65.90.100.1 255.255.255.255 6 | router bgp 65001 7 | network 10.0.0.0 255.255.255.0 8 | +++++++++++++++++++ 9 | hostname CORE_SW2 10 | interface loopback0 11 | management interface CORE_SW2 12 | 65.90.100.2 255.255.255.255 13 | router bgp 65001 14 | network 10.0.0.0 255.255.255.0 15 | +++++++++++++++++++ 16 | hostname CORE_SW3 17 | interface Loopback1 18 | Test Loopback on CORE_SW3 19 | 10.10.10.2 255.255.255.255 20 | router ospf 100 21 | network 10.10.10.0 255.255.255.0 22 | pi@RaspPi4:~/Coding/Go_folder/netOps $ 23 | -------------------------------------------------------------------------------- /misc_folder/struct_switch_break_loop.go: -------------------------------------------------------------------------------- 1 | //Structin my stuff playin with switches while breakin loops 2 | 3 | package main 4 | 5 | import "fmt" 6 | 7 | // taking a structure 8 | type device_id struct { 9 | // taking variables 10 | name string 11 | cmds []string 12 | } 13 | 14 | // Main Function 15 | func main() { 16 | 17 | // creating the instance of the 18 | // device_id struct type 19 | r1 := &device_id{ 20 | name: "cmh1.r1", 21 | cmds: []string{"config t", "router ospf 1", "network 10.0.0.0/24"}, 22 | } 23 | r2 := &device_id{ 24 | name: "cmh1.r2", 25 | cmds: []string{"config t", "router ospf 1", "network 10.0.1.0/24"}, 26 | } 27 | r3 := &device_id{ 28 | name: "cmh1.r3", 29 | cmds: []string{"config t", "router ospf 1", "network 10.0.2.0/24"}, 30 | } 31 | 32 | routerId := []string{(*r1).name, (*r2).name, (*r3).name} 33 | routerCmds := [][]string{(*r1).cmds, (*r2).cmds, (*r3).cmds} 34 | 35 | //fmt.Println(routerId) 36 | //fmt.Println((*r3).cmds) 37 | //fmt.Println(routerCmds) 38 | 39 | target:= routerId[1] 40 | fmt.Println("Switch target is:", target) 41 | Loop: 42 | for i := 0; i < len(routerId); i++ { 43 | fmt.Println("Times through loop:", i) 44 | switch target { 45 | case routerId[0]: 46 | fmt.Println("Target is: ", routerId[0]) 47 | for i := range routerCmds[0] { 48 | fmt.Println(routerCmds[0][i]) 49 | } 50 | fmt.Println("R1 done") 51 | break Loop 52 | case routerId[1]: 53 | fmt.Println("Target is: ", routerId[1]) 54 | for i := range routerCmds[1] { 55 | fmt.Println(routerCmds[1][i]) 56 | } 57 | fmt.Println("R2 done") 58 | break Loop 59 | case routerId[2]: 60 | fmt.Println("Target is: ", routerId[2]) 61 | for i := range routerCmds[2] { 62 | fmt.Println(routerCmds[2][i]) 63 | } 64 | fmt.Println("R3 done") 65 | break Loop 66 | 67 | } 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /misc_folder/struct_switch_break_loop_output.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/misc_stuff $ go run struct_switch_loop_break.go 2 | Switch target is: cmh1.r2 3 | Times through loop: 0 4 | Target is: cmh1.r2 5 | config t 6 | router ospf 1 7 | network 10.0.1.0/24 8 | R2 done 9 | -------------------------------------------------------------------------------- /scp_client/README.md: -------------------------------------------------------------------------------- 1 | In its current format the way to run this app is to update the filename os.Open("xxx.txt") in main.go 2 | with the file you want to transfer to the device. Make sure you add the file to the scp_client folder. 3 | Then issue go run main.go or go build then run the app with ./scp_client 4 | 5 | To customize for your needs you would want update host and login info as well as file you're going to transfer. 6 | 7 | ``` 8 | vi main.go 9 | 10 | src, err := os.Open("xxx.txt") //.txt,.cfg,,,etc 11 | user := "xxx" 12 | pass := "xxx" 13 | targethost := "hostname_or_ip:port" 14 | ``` 15 | 16 | Local directory setup for demo: 17 | 18 | ``` 19 | pi@raspberrypi:~/Code_folder/go_folder/go2run/scp_client $ ls -l 20 | total 3844 21 | -rw-r--r-- 1 pi pi 5293 Dec 5 12:06 README.md 22 | -rw-r--r-- 1 pi pi 233 Dec 5 10:56 go.mod 23 | -rw-r--r-- 1 pi pi 1284 Dec 5 10:19 go.sum 24 | -rw-r--r-- 1 pi pi 1106 Dec 5 11:48 main.go 25 | -rwxr-xr-x 1 pi pi 3904571 Dec 5 11:39 scp_client 26 | -rw-r--r-- 1 pi pi 129 Dec 5 10:55 testfile001.txt 27 | pi@raspberrypi:~/Code_folder/go_folder/go2run/scp_client $ 28 | 29 | ``` 30 | 31 | 32 | 33 | 34 | Script results: 35 | ``` 36 | testfile001.txt does not exist on destination host... 37 | 38 | csr1000v-1#dir 39 | Directory of bootflash:/ 40 | 41 | 201601 drwx 24576 Dec 5 2020 16:20:13 +00:00 tracelogs 42 | 193537 drwx 4096 Dec 5 2020 10:52:06 +00:00 gs_script 43 | 225793 drwx 4096 Dec 5 2020 10:39:02 +00:00 SHARED-IOX 44 | 217729 drwx 4096 Dec 5 2020 10:34:42 +00:00 iox_host_data_share 45 | 209665 drwx 4096 Dec 5 2020 10:34:42 +00:00 guest-share 46 | 80641 drwx 4096 Dec 3 2020 22:18:39 +00:00 .installer 47 | 22 -rw- 157 Dec 3 2020 22:17:57 +00:00 csrlxc-cfg.log 48 | 137089 drwx 4096 Dec 3 2020 22:17:57 +00:00 license_evlog 49 | 19 -rw- 2288 Dec 3 2020 22:17:55 +00:00 cvac.log 50 | 18 -rw- 30 Dec 3 2020 22:17:53 +00:00 throughput_monitor_params 51 | 15 -rw- 1216 Dec 3 2020 22:16:40 +00:00 mode_event_log 52 | 64513 drwx 4096 Sep 1 2020 14:51:38 +00:00 .dbpersist 53 | 274177 drwx 4096 Sep 1 2020 14:51:34 +00:00 onep 54 | 21 -rw- 16 Sep 1 2020 14:51:32 +00:00 ovf-env.xml.md5 55 | 20 -rw- 1 Sep 1 2020 14:51:32 +00:00 .cvac_version 56 | 104833 drwx 4096 Sep 1 2020 14:51:29 +00:00 pnp-info 57 | 145153 drwx 4096 Sep 1 2020 14:50:48 +00:00 virtual-instance 58 | 17 -rwx 1314 Sep 1 2020 14:50:21 +00:00 trustidrootx3_ca.ca 59 | 16 -rw- 20109 Sep 1 2020 14:50:21 +00:00 ios_core.p7b 60 | 40321 drwx 4096 Sep 1 2020 14:50:16 +00:00 core 61 | 169345 drwx 4096 Sep 1 2020 14:50:12 +00:00 bootlog_history 62 | 161281 drwx 4096 Sep 1 2020 14:50:07 +00:00 .prst_sync 63 | 14 -rw- 1105 Sep 1 2020 14:49:08 +00:00 packages.conf 64 | 13 -rw- 48321761 Sep 1 2020 14:49:08 +00:00 csr1000v-rpboot.17.03.01a.SPA.pkg 65 | 12 -rw- 470611036 Sep 1 2020 14:49:08 +00:00 csr1000v-mono-universalk9.17.03.01a.SPA.pkg 66 | 8065 drwx 4096 Sep 1 2020 14:49:03 +00:00 .rollback_timer 67 | 11 drwx 16384 Sep 1 2020 14:48:15 +00:00 lost+found 68 | 69 | 6286540800 bytes total (4401459200 bytes free) 70 | csr1000v-1#exit 71 | Connection to sandbox-iosxe-latest-1.cisco.com closed by remote host. 72 | Connection to sandbox-iosxe-latest-1.cisco.com closed. 73 | 74 | Run script to put testfile001.txt on remote host 75 | 76 | pi@raspberrypi:~/Code_folder/go_folder/go2run/scp_client $ ./scp_client 77 | success 78 | 79 | 80 | pi@raspberrypi:~/Code_folder/go_folder/go2run/scp_client $ ssh developer@sandbox-iosxe-latest-1.cisco.com 81 | Password: 82 | 83 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 84 | 85 | The following programmability features are already enabled: 86 | - NETCONF 87 | - RESTCONF 88 | 89 | Thanks for stopping by. 90 | 91 | 92 | csr1000v-1#dir 93 | Directory of bootflash:/ 94 | 95 | 201601 drwx 24576 Dec 5 2020 16:23:20 +00:00 tracelogs 96 | 23 -rw- 129 Dec 5 2020 16:23:03 +00:00 testfile001.txt <-- File was copied over 97 | 193537 drwx 4096 Dec 5 2020 10:52:06 +00:00 gs_script 98 | 225793 drwx 4096 Dec 5 2020 10:39:02 +00:00 SHARED-IOX 99 | 217729 drwx 4096 Dec 5 2020 10:34:42 +00:00 iox_host_data_share 100 | 209665 drwx 4096 Dec 5 2020 10:34:42 +00:00 guest-share 101 | 80641 drwx 4096 Dec 3 2020 22:18:39 +00:00 .installer 102 | 22 -rw- 157 Dec 3 2020 22:17:57 +00:00 csrlxc-cfg.log 103 | 137089 drwx 4096 Dec 3 2020 22:17:57 +00:00 license_evlog 104 | 19 -rw- 2288 Dec 3 2020 22:17:55 +00:00 cvac.log 105 | 18 -rw- 30 Dec 3 2020 22:17:53 +00:00 throughput_monitor_params 106 | 15 -rw- 1216 Dec 3 2020 22:16:40 +00:00 mode_event_log 107 | 64513 drwx 4096 Sep 1 2020 14:51:38 +00:00 .dbpersist 108 | 274177 drwx 4096 Sep 1 2020 14:51:34 +00:00 onep 109 | 21 -rw- 16 Sep 1 2020 14:51:32 +00:00 ovf-env.xml.md5 110 | 20 -rw- 1 Sep 1 2020 14:51:32 +00:00 .cvac_version 111 | 104833 drwx 4096 Sep 1 2020 14:51:29 +00:00 pnp-info 112 | 145153 drwx 4096 Sep 1 2020 14:50:48 +00:00 virtual-instance 113 | 17 -rwx 1314 Sep 1 2020 14:50:21 +00:00 trustidrootx3_ca.ca 114 | 16 -rw- 20109 Sep 1 2020 14:50:21 +00:00 ios_core.p7b 115 | 116 | csr1000v-1#more testfile001.txt 117 | Testfile001.txt 118 | 119 | 120 | This is being used to test scp functionality. 121 | 122 | If you are reading this on the remote host test was successful. 123 | 124 | 125 | csr1000v-1#delete testfile001.txt 126 | Delete filename [testfile001.txt]? 127 | Delete bootflash:/testfile001.txt? [confirm] 128 | csr1000v-1#exit 129 | Connection to sandbox-iosxe-latest-1.cisco.com closed by remote host. 130 | Connection to sandbox-iosxe-latest-1.cisco.com closed. 131 | pi@raspberrypi:~/Code_folder/go_folder/go2run/scp_client $ 132 | 133 | ``` 134 | 135 | -------------------------------------------------------------------------------- /scp_client/archive/hello.txt: -------------------------------------------------------------------------------- 1 | hello, this is a file for testing scp 2 | 3 | blah 4 | blah 5 | blah 6 | 7 | -------------------------------------------------------------------------------- /scp_client/archive/scp_client_v1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net" 7 | "os" 8 | 9 | "golang.org/x/crypto/ssh" 10 | "golang.org/x/crypto/ssh/agent" 11 | 12 | "github.com/tmc/scp" 13 | ) 14 | 15 | func getAgent() (agent.Agent, error) { 16 | agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")) 17 | return agent.NewClient(agentConn), err 18 | } 19 | 20 | func main() { 21 | src, err := os.Open("hello.txt") 22 | if err != nil { 23 | fmt.Println(err) 24 | } 25 | src.Close() 26 | 27 | user := "developer" 28 | pass := "C1sco12345" 29 | targethost := "ios-xe-mgmt-latest.cisco.com:8181" 30 | 31 | client, err := ssh.Dial("tcp", targethost, &ssh.ClientConfig{ 32 | User: user, 33 | Auth: []ssh.AuthMethod{ 34 | ssh.Password(pass), 35 | }, 36 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), // FIXME: please be more secure in checking host keys 37 | }) 38 | if err != nil { 39 | log.Fatalln("Failed to dial:", err) 40 | } 41 | 42 | session, err := client.NewSession() 43 | if err != nil { 44 | log.Fatalln("Failed to create session: " + err.Error()) 45 | } 46 | 47 | dest := src.Name() + "-copy" 48 | err = scp.CopyPath(src.Name(), dest, session) 49 | if _, err := os.Stat(dest); os.IsNotExist(err) { 50 | fmt.Printf("no such file or directory: %s", dest) 51 | } else { 52 | fmt.Println("success") 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /scp_client/copy_dir/scp_clientv3.go: -------------------------------------------------------------------------------- 1 | /* 2 | This script will copy a directory and its contents over to a remote device. 3 | One of the challenges is that the directory needed to be created on the remote device prior to copying files over. 4 | */ 5 | 6 | package main 7 | 8 | import ( 9 | "fmt" 10 | "golang.org/x/crypto/ssh" 11 | "golang.org/x/crypto/ssh/agent" 12 | "log" 13 | "net" 14 | "os" 15 | 16 | "github.com/tmc/scp" 17 | ) 18 | 19 | func getAgent() (agent.Agent, error) { 20 | agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")) 21 | return agent.NewClient(agentConn), err 22 | } 23 | 24 | func scpFunc(dir, file string) { 25 | f := dir + "/" + file 26 | src, err := os.Open(f) 27 | if err != nil { 28 | fmt.Println(err) 29 | } 30 | src.Close() 31 | user := "developer" 32 | pass := "C1sco12345" 33 | host := "sandbox-iosxe-latest-1.cisco.com:22" 34 | 35 | client, err := ssh.Dial("tcp", host, &ssh.ClientConfig{ 36 | User: user, 37 | Auth: []ssh.AuthMethod{ 38 | ssh.Password(pass), 39 | }, 40 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), // FIXME: please be more secure in checking host keys 41 | }) 42 | if err != nil { 43 | log.Fatalln("Failed to dial:", err) 44 | } 45 | 46 | session, err := client.NewSession() 47 | if err != nil { 48 | log.Fatalln("Failed to create session: " + err.Error()) 49 | } 50 | dest := src.Name() 51 | err = scp.CopyPath(src.Name(), dest, session) 52 | if _, err := os.Stat(dest); os.IsNotExist(err) { 53 | fmt.Printf("no such file or directory: %s", dest) 54 | } else { 55 | fmt.Println("success") 56 | } 57 | } 58 | 59 | func createDir(dir string) { 60 | user := "developer" 61 | pass := "C1sco12345" 62 | host := "sandbox-iosxe-latest-1.cisco.com:22" 63 | 64 | client, err := ssh.Dial("tcp", host, &ssh.ClientConfig{ 65 | User: user, 66 | Auth: []ssh.AuthMethod{ 67 | ssh.Password(pass), 68 | }, 69 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), // FIXME: please be more secure in checking host keys 70 | }) 71 | if err != nil { 72 | log.Fatalln("Failed to dial:", err) 73 | } 74 | 75 | session, err := client.NewSession() 76 | if err != nil { 77 | log.Fatalln("Failed to create session: " + err.Error()) 78 | } 79 | stdin, _ := session.StdinPipe() 80 | session.Stdout = os.Stdout 81 | session.Stderr = os.Stderr 82 | session.Shell() 83 | fmt.Fprintf(stdin, "mkdir "+dir+"\n") 84 | fmt.Fprintf(stdin, "\n\n\n") 85 | fmt.Fprintf(stdin, "exit\n") 86 | session.Wait() 87 | session.Close() 88 | } 89 | 90 | func main() { 91 | dir := "test_dir" 92 | createDir(dir) 93 | files, err := os.ReadDir(dir) 94 | if err != nil { 95 | log.Fatal(err) 96 | } 97 | 98 | for _, file := range files { 99 | fmt.Println(file.Name()) 100 | scpFunc(dir, file.Name()) 101 | } 102 | 103 | } 104 | 105 | 106 | 107 | /* 108 | pi@raspberrypi:~/Code_folder/go_folder/netOps/scp_client $ ls -l 109 | total 3776 110 | -rw-r--r-- 1 pi pi 257 Feb 25 22:40 go.mod 111 | -rw-r--r-- 1 pi pi 1384 Feb 25 22:40 go.sum 112 | -rwxr-xr-x 1 pi pi 3842756 Feb 25 22:55 scp_client 113 | -rw-r--r-- 1 pi pi 2095 Feb 25 23:57 scp_clientv3.go 114 | drwxr-xr-x 2 pi pi 4096 Feb 25 23:12 test_dir 115 | pi@raspberrypi:~/Code_folder/go_folder/netOps/scp_client $ cd test_dir/ 116 | pi@raspberrypi:~/Code_folder/go_folder/netOps/scp_client/test_dir $ ls -l 117 | total 12 118 | -rw-r--r-- 1 pi pi 8 Feb 25 23:12 text1.txt 119 | -rw-r--r-- 1 pi pi 7 Feb 25 22:38 text2.txt 120 | -rw-r--r-- 1 pi pi 7 Feb 25 22:39 text3.txt 121 | pi@raspberrypi:~/Code_folder/go_folder/netOps/scp_client/test_dir $ 122 | 123 | pi@raspberrypi:~/Code_folder/go_folder/netOps/scp_client $ go run scp_clientv3.go 124 | 125 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 126 | 127 | The following programmability features are already enabled: 128 | - NETCONF 129 | - RESTCONF 130 | 131 | Thanks for stopping by. 132 | 133 | 134 | csr1000v-1#mkdir test_dir 135 | Create directory filename [test_dir]? 136 | Created dir bootflash:/test_dir 137 | csr1000v-1# 138 | csr1000v-1# 139 | csr1000v-1#exit 140 | text1.txt 141 | success 142 | text2.txt 143 | success 144 | text3.txt 145 | success 146 | pi@raspberrypi:~/Code_folder/go_folder/netOps/scp_client $ 147 | 148 | 149 | //remote device// 150 | 151 | csr1000v-1#dir 152 | Directory of bootflash:/ 153 | 154 | 201601 drwx 20480 Feb 26 2021 05:08:57 +00:00 tracelogs 155 | 153217 drwx 4096 Feb 26 2021 04:58:12 +00:00 test_dir 156 | 241921 drwx 4096 Feb 26 2021 04:47:23 +00:00 exit 157 | 80641 drwx 4096 Feb 25 2021 23:49:45 +00:00 .installer 158 | 22 -rw- 157 Feb 25 2021 23:49:04 +00:00 csrlxc-cfg.log 159 | 137089 drwx 4096 Feb 25 2021 23:49:04 +00:00 license_evlog 160 | 19 -rw- 2288 Feb 25 2021 23:49:02 +00:00 cvac.log 161 | 18 -rw- 30 Feb 25 2021 23:49:00 +00:00 throughput_monitor_params 162 | 15 -rw- 1216 Feb 25 2021 23:48:06 +00:00 mode_event_log 163 | 64513 drwx 4096 Sep 1 2020 14:51:38 +00:00 .dbpersist 164 | 274177 drwx 4096 Sep 1 2020 14:51:34 +00:00 onep 165 | 21 -rw- 16 Sep 1 2020 14:51:32 +00:00 ovf-env.xml.md5 166 | 20 -rw- 1 Sep 1 2020 14:51:32 +00:00 .cvac_version 167 | 104833 drwx 4096 Sep 1 2020 14:51:29 +00:00 pnp-info 168 | 145153 drwx 4096 Sep 1 2020 14:50:48 +00:00 virtual-instance 169 | 17 -rwx 1314 Sep 1 2020 14:50:21 +00:00 trustidrootx3_ca.ca 170 | 16 -rw- 20109 Sep 1 2020 14:50:21 +00:00 ios_core.p7b 171 | 193537 drwx 4096 Sep 1 2020 14:50:18 +00:00 gs_script 172 | 40321 drwx 4096 Sep 1 2020 14:50:16 +00:00 core 173 | 169345 drwx 4096 Sep 1 2020 14:50:12 +00:00 bootlog_history 174 | 161281 drwx 4096 Sep 1 2020 14:50:07 +00:00 .prst_sync 175 | 14 -rw- 1105 Sep 1 2020 14:49:08 +00:00 packages.conf 176 | 13 -rw- 48321761 Sep 1 2020 14:49:08 +00:00 csr1000v-rpboot.17.03.01a.SPA.pkg 177 | 12 -rw- 470611036 Sep 1 2020 14:49:08 +00:00 csr1000v-mono-universalk9.17.03.01a.SPA.pkg 178 | 8065 drwx 4096 Sep 1 2020 14:49:03 +00:00 .rollback_timer 179 | 11 drwx 16384 Sep 1 2020 14:48:15 +00:00 lost+found 180 | 181 | 6286540800 bytes total (5434560512 bytes free) 182 | csr1000v-1#cd test 183 | csr1000v-1#cd test_dir 184 | csr1000v-1#dir 185 | Directory of bootflash:/test_dir/ 186 | 187 | 153220 -rw- 7 Feb 26 2021 04:58:12 +00:00 text3.txt 188 | 153219 -rw- 7 Feb 26 2021 04:58:11 +00:00 text2.txt 189 | 153218 -rw- 8 Feb 26 2021 04:58:10 +00:00 text1.txt 190 | 191 | 6286540800 bytes total (5434560512 bytes free) 192 | csr1000v-1# 193 | */ 194 | -------------------------------------------------------------------------------- /scp_client/go.mod: -------------------------------------------------------------------------------- 1 | module scp_client 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect 7 | github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef 8 | golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c 9 | ) 10 | -------------------------------------------------------------------------------- /scp_client/go.sum: -------------------------------------------------------------------------------- 1 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= 2 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= 3 | github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef h1:7D6Nm4D6f0ci9yttWaKjM1TMAXrH5Su72dojqYGntFY= 4 | github.com/tmc/scp v0.0.0-20170824174625-f7b48647feef/go.mod h1:WLFStEdnJXpjK8kd4qKLwQKX/1vrDzp5BcDyiZJBHJM= 5 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 6 | golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c h1:9HhBz5L/UjnK9XLtiZhYAdue5BVKep3PMmS2LuPDt8k= 7 | golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= 8 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 9 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 10 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 11 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 12 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 13 | -------------------------------------------------------------------------------- /scp_client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "golang.org/x/crypto/ssh" 6 | "golang.org/x/crypto/ssh/agent" 7 | "log" 8 | "net" 9 | "os" 10 | 11 | "github.com/tmc/scp" 12 | ) 13 | 14 | func getAgent() (agent.Agent, error) { 15 | agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")) 16 | return agent.NewClient(agentConn), err 17 | } 18 | 19 | func main() { 20 | src, err := os.Open("<>") 21 | if err != nil { 22 | fmt.Println(err) 23 | } 24 | src.Close() 25 | user := "<>" 26 | pass := "<>" 27 | host := ":" 28 | 29 | client, err := ssh.Dial("tcp", host, &ssh.ClientConfig{ 30 | User: user, 31 | Auth: []ssh.AuthMethod{ 32 | ssh.Password(pass), 33 | }, 34 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), // FIXME: please be more secure in checking host keys 35 | }) 36 | if err != nil { 37 | log.Fatalln("Failed to dial:", err) 38 | } 39 | 40 | session, err := client.NewSession() 41 | if err != nil { 42 | log.Fatalln("Failed to create session: " + err.Error()) 43 | } 44 | 45 | dest := src.Name() 46 | err = scp.CopyPath(src.Name(), dest, session) 47 | if _, err := os.Stat(dest); os.IsNotExist(err) { 48 | fmt.Printf("no such file or directory: %s", dest) 49 | } else { 50 | fmt.Println("success") 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/can_I_ssh_script.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "golang.org/x/crypto/ssh" 7 | "log" 8 | ) 9 | 10 | func main() { 11 | 12 | config := &ssh.ClientConfig{ 13 | User: "root", 14 | Auth: []ssh.AuthMethod{ssh.Password("D_Vay!_10&")}, 15 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 16 | } 17 | client, err := ssh.Dial("tcp", "ios-xe-mgmt.cisco.com:8181", config) 18 | if err != nil { 19 | log.Fatal("Failed to dial: ", err) 20 | } 21 | 22 | // Each ClientConn can support multiple interactive sessions, 23 | // represented by a Session. 24 | session, err := client.NewSession() 25 | if err != nil { 26 | log.Fatal("Failed to create session: ", err) 27 | } 28 | defer session.Close() 29 | 30 | // Once a Session is created, you can execute a single command on 31 | // the remote side using the Run method. 32 | var b bytes.Buffer 33 | session.Stdout = &b 34 | if err := session.Run("show ip int brief"); err != nil { 35 | log.Fatal("Failed to run: " + err.Error()) 36 | } 37 | fmt.Println(b.String()) 38 | } 39 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/can_I_ssh_script_output.txt: -------------------------------------------------------------------------------- 1 | Todds-MBP:go_code_folder toddriemenschneider$ go run can_I_ssh_script.go 2 | 3 | Welcome to the DevNet Always On Sandbox for IOS XE 4 | 5 | This is a shared sandbox available for anyone to use to 6 | test APIs, explore features, and test scripts. Please 7 | keep this in mind as you use it, and respect others use. 8 | 9 | The following programmability features are already enabled: 10 | - NETCONF 11 | - RESTCONF 12 | 13 | Thanks for stopping by. 14 | 15 | 16 | 17 | Interface IP-Address OK? Method Status Protocol 18 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 19 | GigabitEthernet2 9.9.9.9 YES other up up 20 | GigabitEthernet3 100.100.100.100 YES other up up 21 | Todds-MBP:go_code_folder toddriemenschneider$ 22 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/cmd_file.txt: -------------------------------------------------------------------------------- 1 | enable 2 | term len 0 3 | config t 4 | interface loopback 72 5 | description golang test script 6 | exit 7 | exit 8 | show run interface loopback72 9 | 10 | show ip int brief 11 | exit 12 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/cmd_file001.txt: -------------------------------------------------------------------------------- 1 | enable 2 | term len 0 3 | config t 4 | interface loopback 72 5 | description testing go_ssh 6 | exit 7 | exit 8 | show run int loopback 72 9 | config t 10 | interface loopback71 11 | description testing go_ssh 12 | exit 13 | exit 14 | sh run int loopback 71 15 | 16 | show ip int brief 17 | show ip route summ 18 | show cdp neighbor 19 | show arp 20 | show version 21 | exit 22 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/cmd_file2.txt: -------------------------------------------------------------------------------- 1 | enable 2 | show ip route 3 | show version | inc IOS 4 | exit 5 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/go_ssh_script_2.go: -------------------------------------------------------------------------------- 1 | // This script is used to run show commands on a cisco devnet device 2 | // I used a map to create the command set that will be run on the device 3 | // The for loop allows us to run multiple commands on the device. 4 | // (c) 2019 Todd Riemenschneider 5 | 6 | package main 7 | 8 | import ( 9 | "bytes" 10 | "fmt" 11 | "golang.org/x/crypto/ssh" 12 | "log" 13 | ) 14 | 15 | func main() { 16 | // Used a map to build my command set 17 | commands := map[string]string{"a":"show ip arp", "b":"show version", "c":"show ip route summ"} 18 | // SSH Creds to log into remote device 19 | config := &ssh.ClientConfig{ 20 | User: "root", 21 | Auth: []ssh.AuthMethod{ssh.Password("D_Vay!_10&")}, 22 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 23 | } 24 | // Used for loop to run through command set, "_" throws away the key data while v represents the actual command 25 | for _, v := range commands { 26 | //This is who the script will be logging into 27 | client, err := ssh.Dial("tcp", "ios-xe-mgmt.cisco.com:8181", config) 28 | if err != nil { 29 | log.Fatal("Failed to dial: ", err) 30 | } 31 | //This initiates the connection to the remote device 32 | session, err := client.NewSession() 33 | if err != nil { 34 | log.Fatal("Failed to create session: ", err) 35 | } 36 | defer session.Close() 37 | // Defines a variable to capture the output of the commands being run 38 | var cmd_output bytes.Buffer 39 | session.Stdout = &cmd_output 40 | fmt.Printf("**** %s *** ", v) 41 | //This is where the commands actually being sent to the remote device 42 | session.Run(v) 43 | // Prints output to screen 44 | fmt.Println(cmd_output.String()) 45 | fmt.Printf("###########\n") 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/go_ssh_script_2_output.txt: -------------------------------------------------------------------------------- 1 | 2 | pi@raspberrypi:~/Coding_Folder $ go run go_ssh_script_2.go 3 | **** show ip arp *** 4 | Welcome to the DevNet Always On Sandbox for IOS XE 5 | 6 | This is a shared sandbox available for anyone to use to 7 | test APIs, explore features, and test scripts. Please 8 | keep this in mind as you use it, and respect others use. 9 | 10 | The following programmability features are already enabled: 11 | - NETCONF 12 | - RESTCONF 13 | 14 | Thanks for stopping by. 15 | 16 | 17 | 18 | Protocol Address Age (min) Hardware Addr Type Interface 19 | Internet 10.10.20.48 - 0050.56bb.18c4 ARPA GigabitEthernet1 20 | Internet 10.10.20.253 0 0896.ad9e.444c ARPA GigabitEthernet1 21 | Internet 10.10.20.254 228 0008.e3ff.fd90 ARPA GigabitEthernet1 22 | Internet 10.255.255.1 - 0050.56bb.ac30 ARPA GigabitEthernet2 23 | Internet 100.100.100.100 - 0050.56bb.1669 ARPA GigabitEthernet3 24 | ########### 25 | **** show version *** 26 | Welcome to the DevNet Always On Sandbox for IOS XE 27 | 28 | This is a shared sandbox available for anyone to use to 29 | test APIs, explore features, and test scripts. Please 30 | keep this in mind as you use it, and respect others use. 31 | 32 | The following programmability features are already enabled: 33 | - NETCONF 34 | - RESTCONF 35 | 36 | Thanks for stopping by. 37 | 38 | 39 | Cisco IOS XE Software, Version 16.08.01 40 | Cisco IOS Software [Fuji], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.8.1, RELEASE SOFTWARE (fc3) 41 | Technical Support: http://www.cisco.com/techsupport 42 | Copyright (c) 1986-2018 by Cisco Systems, Inc. 43 | Compiled Tue 27-Mar-18 13:32 by mcpre 44 | 45 | 46 | Cisco IOS-XE software, Copyright (c) 2005-2018 by cisco Systems, Inc. 47 | All rights reserved. Certain components of Cisco IOS-XE software are 48 | licensed under the GNU General Public License ("GPL") Version 2.0. The 49 | software code licensed under GPL Version 2.0 is free software that comes 50 | with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such 51 | GPL code under the terms of GPL Version 2.0. For more details, see the 52 | documentation or "License Notice" file accompanying the IOS-XE software, 53 | or the applicable URL provided on the flyer accompanying the IOS-XE 54 | software. 55 | 56 | 57 | ROM: IOS-XE ROMMON 58 | 59 | csr1000v uptime is 2 days, 5 hours, 19 minutes 60 | Uptime for this control processor is 2 days, 5 hours, 21 minutes 61 | System returned to ROM by reload 62 | System image file is "bootflash:packages.conf" 63 | Last reload reason: reload 64 | 65 | 66 | 67 | This product contains cryptographic features and is subject to United 68 | States and local country laws governing import, export, transfer and 69 | use. Delivery of Cisco cryptographic products does not imply 70 | third-party authority to import, export, distribute or use encryption. 71 | Importers, exporters, distributors and users are responsible for 72 | compliance with U.S. and local country laws. By using this product you 73 | agree to comply with applicable laws and regulations. If you are unable 74 | to comply with U.S. and local laws, return this product immediately. 75 | 76 | A summary of U.S. laws governing Cisco cryptographic products may be found at: 77 | http://www.cisco.com/wwl/export/crypto/tool/stqrg.html 78 | 79 | If you require further assistance please contact us by sending email to 80 | export@cisco.com. 81 | 82 | License Level: ax 83 | License Type: Default. No valid license found. 84 | Next reload license Level: ax 85 | 86 | cisco CSR1000V (VXE) processor (revision VXE) with 2186344K/3075K bytes of memory. 87 | Processor board ID 9JGOSIUGQVN 88 | 3 Gigabit Ethernet interfaces 89 | 32768K bytes of non-volatile configuration memory. 90 | 3984604K bytes of physical memory. 91 | 7774207K bytes of virtual hard disk at bootflash:. 92 | 0K bytes of WebUI ODM Files at webui:. 93 | 94 | Configuration register is 0x2102 95 | 96 | ########### 97 | pi@raspberrypi:~/Coding_Folder $ 98 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/go_ssh_script_3.go: -------------------------------------------------------------------------------- 1 | // This is my attempt at building viable ssh script to capture data from show commands on Cisco Devnet devices. 2 | // I used a string array to create the command set to loop through. 3 | // (c) 2019 Todd Riemenschneider 4 | 5 | package main 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | "golang.org/x/crypto/ssh" 11 | "log" 12 | ) 13 | 14 | func main() { 15 | 16 | //Create the command set you want using a string array 17 | commands := []string {"show ip arp", "show version"} 18 | 19 | //Client ssh parameters to log in 20 | config := &ssh.ClientConfig{ 21 | User: "root", 22 | Auth: []ssh.AuthMethod{ssh.Password("D_Vay!_10&")}, 23 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 24 | } 25 | //Loop through the command set the "_" is used to ignore the index and the "s" is for string value 26 | for _, s := range commands { 27 | //Who you are connecting to 28 | client, err := ssh.Dial("tcp", "ios-xe-mgmt.cisco.com:8181", config) 29 | if err != nil { 30 | log.Fatal("Failed to dial: ", err) 31 | } 32 | // Initiate connection 33 | session, err := client.NewSession() 34 | if err != nil { 35 | log.Fatal("Failed to create session: ", err) 36 | } 37 | defer session.Close() 38 | //Output variiable 39 | var cmd_output bytes.Buffer 40 | session.Stdout = &cmd_output 41 | //Title the commands being run 42 | fmt.Printf("%s", s) 43 | session.Run(s) 44 | //Print output of commands 45 | fmt.Println(cmd_output.String()) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/go_ssh_script_3_output.txt: -------------------------------------------------------------------------------- 1 | pi@raspberrypi:~/Coding_Folder $ go run go_ssh_script_3.go 2 | show ip arp 3 | Welcome to the DevNet Always On Sandbox for IOS XE 4 | 5 | This is a shared sandbox available for anyone to use to 6 | test APIs, explore features, and test scripts. Please 7 | keep this in mind as you use it, and respect others use. 8 | 9 | The following programmability features are already enabled: 10 | - NETCONF 11 | - RESTCONF 12 | 13 | Thanks for stopping by. 14 | 15 | 16 | 17 | Protocol Address Age (min) Hardware Addr Type Interface 18 | Internet 10.10.20.48 - 0050.56bb.18c4 ARPA GigabitEthernet1 19 | Internet 10.10.20.253 0 0896.ad9e.444c ARPA GigabitEthernet1 20 | Internet 10.10.20.254 250 0008.e3ff.fd90 ARPA GigabitEthernet1 21 | Internet 10.20.30.40 - 0050.56bb.ac30 ARPA GigabitEthernet2 22 | Internet 10.255.255.1 - 0050.56bb.ac30 ARPA GigabitEthernet2 23 | Internet 100.100.100.100 - 0050.56bb.1669 ARPA GigabitEthernet3 24 | show version 25 | Welcome to the DevNet Always On Sandbox for IOS XE 26 | 27 | This is a shared sandbox available for anyone to use to 28 | test APIs, explore features, and test scripts. Please 29 | keep this in mind as you use it, and respect others use. 30 | 31 | The following programmability features are already enabled: 32 | - NETCONF 33 | - RESTCONF 34 | 35 | Thanks for stopping by. 36 | 37 | 38 | Cisco IOS XE Software, Version 16.08.01 39 | Cisco IOS Software [Fuji], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.8.1, RELEASE SOFTWARE (fc3) 40 | Technical Support: http://www.cisco.com/techsupport 41 | Copyright (c) 1986-2018 by Cisco Systems, Inc. 42 | Compiled Tue 27-Mar-18 13:32 by mcpre 43 | 44 | 45 | Cisco IOS-XE software, Copyright (c) 2005-2018 by cisco Systems, Inc. 46 | All rights reserved. Certain components of Cisco IOS-XE software are 47 | licensed under the GNU General Public License ("GPL") Version 2.0. The 48 | software code licensed under GPL Version 2.0 is free software that comes 49 | with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such 50 | GPL code under the terms of GPL Version 2.0. For more details, see the 51 | documentation or "License Notice" file accompanying the IOS-XE software, 52 | or the applicable URL provided on the flyer accompanying the IOS-XE 53 | software. 54 | 55 | 56 | ROM: IOS-XE ROMMON 57 | 58 | csr1000v uptime is 2 days, 9 hours, 55 minutes 59 | Uptime for this control processor is 2 days, 9 hours, 57 minutes 60 | System returned to ROM by reload 61 | System image file is "bootflash:packages.conf" 62 | Last reload reason: reload 63 | 64 | 65 | 66 | This product contains cryptographic features and is subject to United 67 | States and local country laws governing import, export, transfer and 68 | use. Delivery of Cisco cryptographic products does not imply 69 | third-party authority to import, export, distribute or use encryption. 70 | Importers, exporters, distributors and users are responsible for 71 | compliance with U.S. and local country laws. By using this product you 72 | agree to comply with applicable laws and regulations. If you are unable 73 | to comply with U.S. and local laws, return this product immediately. 74 | 75 | A summary of U.S. laws governing Cisco cryptographic products may be found at: 76 | http://www.cisco.com/wwl/export/crypto/tool/stqrg.html 77 | 78 | If you require further assistance please contact us by sending email to 79 | export@cisco.com. 80 | 81 | License Level: ax 82 | License Type: Default. No valid license found. 83 | Next reload license Level: ax 84 | 85 | cisco CSR1000V (VXE) processor (revision VXE) with 2186344K/3075K bytes of memory. 86 | Processor board ID 9JGOSIUGQVN 87 | 3 Gigabit Ethernet interfaces 88 | 32768K bytes of non-volatile configuration memory. 89 | 3984604K bytes of physical memory. 90 | 7774207K bytes of virtual hard disk at bootflash:. 91 | 0K bytes of WebUI ODM Files at webui:. 92 | 93 | Configuration register is 0x2102 94 | 95 | pi@raspberrypi:~/Coding_Folder $ 96 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/host_file001.txt: -------------------------------------------------------------------------------- 1 | ios-xe-mgmt-latest.cisco.com:8181 2 | ios-xe-mgmt-latest.cisco.com:8181 3 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/interactive_ssh.go: -------------------------------------------------------------------------------- 1 | // This is a user interactive ssh script 2 | // You will enter the commands to run at the time you run the script 3 | // (c) 2020 Todd Riemenschneider 4 | 5 | package main 6 | 7 | import ( 8 | "fmt" 9 | "golang.org/x/crypto/ssh" 10 | "log" 11 | "os" 12 | "strings" 13 | ) 14 | 15 | func main() { 16 | user := "developer" 17 | pass := "C1sco12345" 18 | targethost := "ios-xe-mgmt-latest.cisco.com:8181" 19 | 20 | // This will create the list of the commands that you will run 21 | var s, sep string 22 | for i := 1; i < len(os.Args); i++ { 23 | s += sep + os.Args[i] 24 | sep = " " 25 | } 26 | cmds := strings.Split(s, ",") 27 | fmt.Println(cmds) 28 | 29 | config := &ssh.ClientConfig{ 30 | User: user, 31 | Auth: []ssh.AuthMethod{ 32 | ssh.Password(pass), 33 | }, 34 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 35 | } 36 | conn, err := ssh.Dial("tcp", targethost, config) 37 | if err != nil { 38 | log.Fatal("Failed to dial: ", err) 39 | } 40 | sess, err := conn.NewSession() 41 | if err != nil { 42 | log.Fatal("Failed to create session: ", err) 43 | } 44 | stdin, _ := sess.StdinPipe() 45 | sess.Stdout = os.Stdout 46 | sess.Stderr = os.Stderr 47 | sess.Shell() 48 | fmt.Fprintf(stdin, "term len 0\n") 49 | for _, cmd := range cmds { 50 | fmt.Fprintf(stdin, "%s\n", cmd) 51 | } 52 | fmt.Fprintf(stdin, "exit\n") 53 | fmt.Fprintf(stdin, "exit\n") 54 | sess.Wait() 55 | sess.Close() 56 | } 57 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/interactive_ssh_output.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps $ go run interactive_ssh.go show run interface loopback 0, show ip int brief, show version 2 | [show run interface loopback 0 show ip int brief show version] 3 | 4 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 5 | 6 | The following programmability features are already enabled: 7 | - NETCONF 8 | - RESTCONF 9 | 10 | Thanks for stopping by. 11 | 12 | 13 | 14 | csr1000v-1#term len 0 15 | csr1000v-1#show run interface loopback 0 16 | Building configuration... 17 | 18 | Current configuration : 130 bytes 19 | ! 20 | interface Loopback0 21 | ip address 192.0.2.1 255.255.255.255 22 | ip ospf authentication key-chain KC_OSPF_AUTH 23 | ip ospf 1 area 0 24 | end 25 | 26 | csr1000v-1# show ip int brief 27 | Interface IP-Address OK? Method Status Protocol 28 | GigabitEthernet1 10.10.20.48 YES other up up 29 | GigabitEthernet2 192.168.1.149 YES other up up 30 | GigabitEthernet3 1.43.40.3 YES other up up 31 | Loopback0 192.0.2.1 YES manual up up 32 | Loopback1 1.1.1.1 YES manual up up 33 | Loopback2 unassigned YES unset up up 34 | Loopback3 111.1.1.1 YES other up up 35 | Loopback199 172.16.199.1 YES other up up 36 | Tunnel100 192.168.0.66 YES manual up up 37 | csr1000v-1# show version 38 | Cisco IOS XE Software, Version 16.11.01a 39 | Cisco IOS Software [Gibraltar], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.11.1a, RELEASE SOFTWARE (fc1) 40 | Technical Support: http://www.cisco.com/techsupport 41 | Copyright (c) 1986-2019 by Cisco Systems, Inc. 42 | Compiled Thu 11-Apr-19 23:59 by mcpre 43 | 44 | 45 | Cisco IOS-XE software, Copyright (c) 2005-2019 by cisco Systems, Inc. 46 | All rights reserved. Certain components of Cisco IOS-XE software are 47 | licensed under the GNU General Public License ("GPL") Version 2.0. The 48 | software code licensed under GPL Version 2.0 is free software that comes 49 | with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such 50 | GPL code under the terms of GPL Version 2.0. For more details, see the 51 | documentation or "License Notice" file accompanying the IOS-XE software, 52 | or the applicable URL provided on the flyer accompanying the IOS-XE 53 | software. 54 | 55 | 56 | ROM: IOS-XE ROMMON 57 | 58 | csr1000v-1 uptime is 1 week, 13 hours, 46 minutes 59 | Uptime for this control processor is 1 week, 13 hours, 47 minutes 60 | System returned to ROM by reload 61 | System image file is "bootflash:packages.conf" 62 | Last reload reason: reload 63 | 64 | 65 | 66 | This product contains cryptographic features and is subject to United 67 | States and local country laws governing import, export, transfer and 68 | use. Delivery of Cisco cryptographic products does not imply 69 | third-party authority to import, export, distribute or use encryption. 70 | Importers, exporters, distributors and users are responsible for 71 | compliance with U.S. and local country laws. By using this product you 72 | agree to comply with applicable laws and regulations. If you are unable 73 | to comply with U.S. and local laws, return this product immediately. 74 | 75 | A summary of U.S. laws governing Cisco cryptographic products may be found at: 76 | http://www.cisco.com/wwl/export/crypto/tool/stqrg.html 77 | 78 | If you require further assistance please contact us by sending email to 79 | export@cisco.com. 80 | 81 | License Level: ax 82 | License Type: N/A(Smart License Enabled) 83 | Next reload license Level: ax 84 | 85 | 86 | Smart Licensing Status: UNREGISTERED/No Licenses in Use 87 | 88 | cisco CSR1000V (VXE) processor (revision VXE) with 2378575K/3075K bytes of memory. 89 | Processor board ID 9YD4LHWG8FZ 90 | 3 Gigabit Ethernet interfaces 91 | 32768K bytes of non-volatile configuration memory. 92 | 8112832K bytes of physical memory. 93 | 7774207K bytes of virtual hard disk at bootflash:. 94 | 0K bytes of WebUI ODM Files at webui:. 95 | 96 | Configuration register is 0x2102 97 | 98 | csr1000v-1#exit 99 | pi@RaspPi4:~/Coding/Go_folder/netOps $ 100 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ios-xe-mgmt-latest.cisco.com\:8181.cfg: -------------------------------------------------------------------------------- 1 | show interface description 2 | 3 | config t 4 | 5 | interface loopback 71 6 | description Unique_configuration1 7 | no shut 8 | exit 9 | exit 10 | ! 11 | show interface description 12 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ios-xe-mgmt.cisco.com\:8181.cfg: -------------------------------------------------------------------------------- 1 | show interface description 2 | 3 | config t 4 | interface loopback 72 5 | description Unique_config_number_2 6 | no shut 7 | exit 8 | exit 9 | ! 10 | show interface description 11 | 12 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/sbx-nxos-mgmt.cisco.com\:8181.cfg: -------------------------------------------------------------------------------- 1 | show run int eth1/24 2 | 3 | config t 4 | interface Eth1/124 5 | description scripted interface - Go Rules... 6 | end 7 | end 8 | 9 | show run 10 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_client_script_10.go: -------------------------------------------------------------------------------- 1 | // This ssh script will use host_file.txt to determine who to 2 | // login to, and the cmd_file1.txt to determine which commands 3 | // to run. Login creds will be determined by hostname. 4 | // (c) 2020 Todd Riemenschneider 5 | 6 | package main 7 | 8 | import ( 9 | "bufio" 10 | "fmt" 11 | "golang.org/x/crypto/ssh" 12 | "log" 13 | "os" 14 | "time" 15 | ) 16 | 17 | var hostList []string 18 | var user string 19 | var pass string 20 | 21 | func loginHosts() { 22 | hf, _ := os.Open("host_file001.txt") 23 | scanner := bufio.NewScanner(hf) 24 | scanner.Split(bufio.ScanLines) 25 | for scanner.Scan() { 26 | hostList = append(hostList, scanner.Text()) 27 | } 28 | fmt.Println(hostList) 29 | } 30 | 31 | func main() { 32 | loginHosts() 33 | for _, host := range hostList { 34 | if host == "ios-xe-mgmt-latest.cisco.com:8181" || host == "ios-xe-mgmt.cisco.com:8181" { 35 | user = "developer" 36 | pass = "C1sco12345" 37 | } else if host == "sbx-nxos-mgmt.cisco.com:8181" { 38 | user = "admin" 39 | pass = "Admin_1234!" 40 | } 41 | targethost := host 42 | 43 | config := &ssh.ClientConfig{ 44 | User: user, 45 | Auth: []ssh.AuthMethod{ 46 | ssh.Password(pass), 47 | }, 48 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 49 | } 50 | 51 | conn, err := ssh.Dial("tcp", targethost, config) 52 | time.Sleep(1) 53 | //Used for troubleshooting 54 | //fmt.Println(conn) 55 | if err != nil { 56 | log.Fatal("Failed to dial: ", err) 57 | } 58 | sess, err := conn.NewSession() 59 | if err != nil { 60 | log.Fatal("Failed to create session: ", err) 61 | } 62 | stdin, err := sess.StdinPipe() 63 | sess.Stdout = os.Stdout 64 | sess.Stderr = os.Stderr 65 | sess.Shell() 66 | // cmds file should use host.cfg name standard 67 | fmt.Println("This is the config file named:" + host + ".cfg") 68 | fmt.Printf("\n\n\n\n") 69 | cmds, _ := os.Open(host + ".cfg") 70 | scanner := bufio.NewScanner(cmds) 71 | scanner.Split(bufio.ScanLines) 72 | var lines []string 73 | for scanner.Scan() { 74 | lines = append(lines, scanner.Text()) 75 | } 76 | cmds.Close() 77 | for _, line := range lines { 78 | fmt.Fprintf(stdin, "%s\n", line) 79 | } 80 | fmt.Fprintf(stdin, "exit\n") 81 | fmt.Fprintf(stdin, "exit\n") 82 | sess.Wait() 83 | sess.Close() 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_client_script_10_output.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder $ go run ssh_client_script_10.go 2 | [sbx-nxos-mgmt.cisco.com:8181 ios-xe-mgmt-latest.cisco.com:8181 ios-xe-mgmt.cisco.com:8181] 3 | This is the config file named:sbx-nxos-mgmt.cisco.com:8181.cfg 4 | 5 | 6 | 7 | 8 | 9 | stty: standard input: Inappropriate ioctl for device 10 | 11 | !Command: show running-config interface Ethernet1/24 12 | !Running configuration last done at: Mon Apr 6 22:35:03 2020 13 | !Time: Mon Apr 6 22:39:13 2020 14 | 15 | version 9.2(1) Bios:version 16 | 17 | interface Ethernet1/24 18 | 19 | 20 | !Command: show running-config 21 | !Running configuration last done at: Mon Apr 6 22:39:13 2020 22 | !Time: Mon Apr 6 22:39:13 2020 23 | 24 | version 9.2(1) Bios:version 25 | hostname sbx-n9kv-ao 26 | vdc sbx-n9kv-ao id 1 27 | limit-resource vlan minimum 16 maximum 4094 28 | limit-resource vrf minimum 2 maximum 4096 29 | limit-resource port-channel minimum 0 maximum 511 30 | limit-resource u4route-mem minimum 248 maximum 248 31 | limit-resource u6route-mem minimum 96 maximum 96 32 | limit-resource m4route-mem minimum 58 maximum 58 33 | limit-resource m6route-mem minimum 8 maximum 8 34 | 35 | feature nxapi 36 | feature bash-shell 37 | feature scp-server 38 | feature ospf 39 | feature bgp 40 | feature netconf 41 | feature restconf 42 | feature grpc 43 | feature interface-vlan 44 | 45 | username admin password 5 $5$XTwcELLF$8Ybmi8D344YTimHFvg02mxS/KeLE8klvBgTqgYjvfL7 role network-admin 46 | 47 | banner motd ^ 48 | Welcome to the DevNet Always On Sandbox for Open NX-OS 49 | 50 | This is a shared sandbox available for anyone to use to 51 | test APIs, explore features, and test scripts. Please 52 | keep this in mind as you use it, and respect others use. 53 | 54 | The following programmability features are already enabled: 55 | - NX-API 56 | - NETCONF, RESTCONF, gRPC 57 | - Native NX-OS and OpenConfig YANG Models 58 | 59 | Thanks for stopping by. 60 | ^ 61 | 62 | ip domain-lookup 63 | radius-server host 172.16.1.12 key 7 "VwritosWsgsziGio" authentication accounting 64 | radius-server host 172.16.1.13 key 7 "VwritosWsgsziGio" authentication accounting 65 | aaa group server radius AAA-Radius-Group 66 | server 172.16.1.12 67 | server 172.16.1.13 68 | use-vrf management 69 | source-interface mgmt0 70 | copp profile strict 71 | snmp-server contact DevNet-Sandbox 72 | snmp-server location Always-On-Sandbox 73 | snmp-server source-interface traps mgmt0 74 | snmp-server user admin network-admin auth md5 0x16279c7eca7d5524934154dd17520e0c priv 0x16279c7eca7d5524934154dd17520e0c localizedkey 75 | rmon event 1 description FATAL(1) owner PMON@FATAL 76 | rmon event 2 description CRITICAL(2) owner PMON@CRITICAL 77 | rmon event 3 description ERROR(3) owner PMON@ERROR 78 | rmon event 4 description WARNING(4) owner PMON@WARNING 79 | rmon event 5 description INFORMATION(5) owner PMON@INFO 80 | snmp-server enable traps callhome event-notify 81 | snmp-server enable traps callhome smtp-send-fail 82 | snmp-server enable traps cfs state-change-notif 83 | snmp-server enable traps cfs merge-failure 84 | snmp-server enable traps aaa server-state-change 85 | snmp-server enable traps feature-control FeatureOpStatusChange 86 | snmp-server enable traps sysmgr cseFailSwCoreNotifyExtended 87 | snmp-server enable traps config ccmCLIRunningConfigChanged 88 | snmp-server enable traps snmp authentication 89 | snmp-server enable traps link cisco-xcvr-mon-status-chg 90 | snmp-server enable traps vtp notifs 91 | snmp-server enable traps vtp vlancreate 92 | snmp-server enable traps vtp vlandelete 93 | snmp-server enable traps bridge newroot 94 | snmp-server enable traps bridge topologychange 95 | snmp-server enable traps stpx inconsistency 96 | snmp-server enable traps stpx root-inconsistency 97 | snmp-server enable traps stpx loop-inconsistency 98 | snmp-server enable traps system Clock-change-notification 99 | snmp-server enable traps feature-control ciscoFeatOpStatusChange 100 | snmp-server enable traps mmode cseNormalModeChangeNotify 101 | snmp-server enable traps mmode cseMaintModeChangeNotify 102 | snmp-server community DevNetSandboxWriteSNMP group network-admin 103 | snmp-server community DevNetSandboxReadSNMP group network-operator 104 | ntp peer 172.16.1.11 use-vrf management key 1 105 | ntp source-interface mgmt0 106 | ntp authenticate 107 | ntp authentication-key 1 md5 QPTFmtc 7 108 | 109 | ip route 1.1.1.1/32 Null0 110 | ip route 1.2.3.4/32 Null0 111 | ip route 6.7.8.9/32 Null0 112 | ip route 8.8.8.8/32 Null0 113 | ip route 10.10.20.2/32 Null0 114 | vlan 1,100-105 115 | vlan 100 116 | name mgmt 117 | vlan 101 118 | name prod 119 | vlan 102 120 | name dev 121 | vlan 103 122 | name test 123 | vlan 104 124 | name security 125 | vlan 105 126 | name iot 127 | 128 | vrf context management 129 | ip route 0.0.0.0/0 10.10.20.254 130 | 131 | interface Vlan1 132 | 133 | interface Vlan100 134 | description mgmt svi - DEMO PLEASE DON'T TOUCH 135 | no shutdown 136 | ip address 172.16.100.1/24 137 | ip router ospf 1 area 0.0.0.0 138 | 139 | interface Vlan101 140 | description prod svi - DEMO PLEASE DON'T TOUCH 141 | no shutdown 142 | ip address 172.16.101.1/24 143 | ip router ospf 1 area 0.0.0.0 144 | 145 | interface Vlan102 146 | description dev svi - DEMO PLEASE DON'T TOUCH 147 | no shutdown 148 | ip address 172.16.102.1/24 149 | ip router ospf 1 area 0.0.0.0 150 | 151 | interface Vlan103 152 | description test svi - DEMO PLEASE DON'T TOUCH 153 | no shutdown 154 | ip address 172.16.103.1/24 155 | ip router ospf 1 area 0.0.0.0 156 | 157 | interface Vlan104 158 | description security svi - DEMO PLEASE DON'T TOUCH 159 | no shutdown 160 | ip address 172.16.104.1/24 161 | ip router ospf 1 area 0.0.0.0 162 | 163 | interface Vlan105 164 | description iot svi - DEMO PLEASE DON'T TOUCH 165 | no shutdown 166 | ip address 172.16.105.1/24 167 | ip router ospf 1 area 0.0.0.0 168 | 169 | interface port-channel11 170 | switchport mode trunk 171 | switchport trunk allowed vlan 100-110 172 | 173 | interface Ethernet1/1 174 | switchport mode trunk 175 | switchport trunk allowed vlan 100-110 176 | channel-group 11 177 | 178 | interface Ethernet1/2 179 | switchport mode trunk 180 | switchport trunk allowed vlan 100-110 181 | channel-group 11 182 | 183 | interface Ethernet1/3 184 | 185 | interface Ethernet1/4 186 | 187 | interface Ethernet1/5 188 | description L3 Link 189 | no switchport 190 | ip address 172.16.1.1/30 191 | ip ospf network broadcast 192 | no ip ospf passive-interface 193 | ip router ospf 1 area 0.0.0.0 194 | no shutdown 195 | 196 | 197 | 198 | interface Ethernet1/124 199 | description scripted interface - Go Rules... 200 | 201 | interface Ethernet1/125 202 | 203 | interface Ethernet1/126 204 | 205 | interface Ethernet1/127 206 | 207 | interface Ethernet1/128 208 | 209 | interface mgmt0 210 | description DO NOT TOUCH CONFIG ON THIS INTERFACE 211 | vrf member management 212 | ip address 10.10.20.95/24 213 | 214 | interface loopback1 215 | ip address 172.16.0.1/32 216 | line console 217 | line vty 218 | boot nxos bootflash:/nxos.9.2.1.bin 219 | router ospf 1 220 | router-id 172.16.0.1 221 | passive-interface default 222 | router bgp 65535 223 | address-family ipv4 unicast 224 | network 172.16.0.0/16 225 | neighbor 172.16.0.2 226 | remote-as 65535 227 | 228 | 229 | This is the config file named:ios-xe-mgmt-latest.cisco.com:8181.cfg 230 | 231 | 232 | 233 | 234 | 235 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 236 | 237 | The following programmability features are already enabled: 238 | - NETCONF 239 | - RESTCONF 240 | 241 | Thanks for stopping by. 242 | 243 | 244 | csr1000v-1#show run int loopback 76 245 | ^ 246 | % Invalid input detected at '^' marker. 247 | 248 | csr1000v-1# 249 | csr1000v-1#config t 250 | Enter configuration commands, one per line. End with CNTL/Z. 251 | csr1000v-1(config)# 252 | csr1000v-1(config)#interface Loopback76 253 | csr1000v-1(config-if)# description scripted with Go 254 | csr1000v-1(config-if)#exit 255 | csr1000v-1(config)#exit 256 | csr1000v-1#! 257 | csr1000v-1#show run int loopback 76 258 | Building configuration... 259 | 260 | Current configuration : 73 bytes 261 | ! 262 | interface Loopback76 263 | description scripted with Go 264 | no ip address 265 | end 266 | 267 | csr1000v-1# 268 | csr1000v-1# 269 | csr1000v-1# 270 | csr1000v-1# 271 | csr1000v-1# 272 | csr1000v-1# 273 | csr1000v-1# 274 | csr1000v-1# 275 | csr1000v-1# 276 | csr1000v-1# 277 | csr1000v-1# 278 | csr1000v-1#exit 279 | This is the config file named:ios-xe-mgmt.cisco.com:8181.cfg 280 | 281 | 282 | 283 | 284 | 285 | 286 | csr1000v#show run int loopback 77 287 | ^ 288 | % Invalid input detected at '^' marker. 289 | 290 | csr1000v# 291 | csr1000v#config t 292 | Enter configuration commands, one per line. End with CNTL/Z. 293 | csr1000v(config)#interface loopback 77 294 | csr1000v(config-if)# description Kickin it with Gophy Style 295 | csr1000v(config-if)# no shut 296 | csr1000v(config-if)#exit 297 | csr1000v(config)#exit 298 | csr1000v#! 299 | csr1000v#show run int loopback 77 300 | Building configuration... 301 | 302 | Current configuration : 83 bytes 303 | ! 304 | interface Loopback77 305 | description Kickin it with Gophy Style 306 | no ip address 307 | end 308 | 309 | csr1000v# 310 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_multi_cmd.go: -------------------------------------------------------------------------------- 1 | // This is a multi-cmd script 2 | // (c) 2019 Todd Riemenschneider 3 | 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | "golang.org/x/crypto/ssh" 9 | "log" 10 | "os" 11 | ) 12 | 13 | func main() { 14 | user := "root" 15 | pass := "D_Vay!_10&" 16 | targethost := "ios-xe-mgmt.cisco.com:8181" 17 | 18 | config := &ssh.ClientConfig{ 19 | User: user, 20 | Auth: []ssh.AuthMethod{ 21 | ssh.Password(pass), 22 | }, 23 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 24 | } 25 | conn, err := ssh.Dial("tcp", targethost, config) 26 | if err != nil { 27 | log.Fatal("Failed to dial: ", err) 28 | } 29 | sess, err := conn.NewSession() 30 | if err != nil { 31 | log.Fatal("Failed to create session: ", err) 32 | } 33 | stdin, _ := sess.StdinPipe() 34 | sess.Stdout = os.Stdout 35 | sess.Stderr = os.Stderr 36 | sess.Shell() 37 | cmds := []string{ 38 | "config t", 39 | "interface loopback 71", 40 | "description golang_test", 41 | "exit", 42 | "exit", 43 | "show run int loopback 71", 44 | "exit"} 45 | for _, cmd := range cmds { 46 | fmt.Fprintf(stdin, "%s\n", cmd) 47 | } 48 | sess.Wait() 49 | sess.Close() 50 | } 51 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_multi_cmd_output.txt: -------------------------------------------------------------------------------- 1 | pi@raspberrypi:~/Coding_Folder $ go run ssh_multi_cmd.go 2 | 3 | Welcome to the DevNet Always On Sandbox for IOS XE 4 | 5 | This is a shared sandbox available for anyone to use to 6 | test APIs, explore features, and test scripts. Please 7 | keep this in mind as you use it, and respect others use. 8 | 9 | The following programmability features are already enabled: 10 | - NETCONF 11 | - RESTCONF 12 | 13 | Thanks for stopping by. 14 | 15 | 16 | 17 | csr1000v#config t 18 | Enter configuration commands, one per line. End with CNTL/Z. 19 | csr1000v(config)#interface loopback 71 20 | csr1000v(config-if)#description golang_test 21 | csr1000v(config-if)#exit 22 | csr1000v(config)#exit 23 | csr1000v#show run int loopback 71 24 | Building configuration... 25 | 26 | Current configuration : 68 bytes 27 | ! 28 | interface Loopback71 29 | description golang_test 30 | no ip address 31 | end 32 | 33 | csr1000v#exit 34 | pi@raspberrypi:~/Coding_Folder $ 35 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_use_cmd_file.go: -------------------------------------------------------------------------------- 1 | // This ssh script will use a command file to push commands/configs to a Cisco IOS device 2 | // (c) 2019 Todd Riemenschneider 3 | 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | "golang.org/x/crypto/ssh" 9 | "log" 10 | "os" 11 | "bufio" 12 | ) 13 | 14 | func main() { 15 | user := "root" 16 | pass := "D_Vay!_10&" 17 | targethost := "ios-xe-mgmt.cisco.com:8181" 18 | 19 | config := &ssh.ClientConfig{ 20 | User: user, 21 | Auth: []ssh.AuthMethod{ 22 | ssh.Password(pass), 23 | }, 24 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 25 | } 26 | conn, err := ssh.Dial("tcp", targethost, config) 27 | if err != nil { 28 | log.Fatal("Failed to dial: ", err) 29 | } 30 | sess, err := conn.NewSession() 31 | if err != nil { 32 | log.Fatal("Failed to create session: ", err) 33 | } 34 | stdin, _ := sess.StdinPipe() 35 | sess.Stdout = os.Stdout 36 | sess.Stderr = os.Stderr 37 | sess.Shell() 38 | fh, _ := os.Open("cmd_file.txt") 39 | scanner := bufio.NewScanner(fh) 40 | scanner.Split(bufio.ScanLines) 41 | var lines []string 42 | for scanner.Scan() { 43 | lines = append(lines, scanner.Text()) 44 | } 45 | fh.Close() 46 | for _, line := range lines { 47 | fmt.Fprintf(stdin, "%s\n", line) 48 | } 49 | sess.Wait() 50 | sess.Close() 51 | } 52 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_use_cmd_file_output.txt: -------------------------------------------------------------------------------- 1 | pi@raspberrypi:~/Coding_Folder $ go run ssh_use_cmd_file.go 2 | 3 | Welcome to the DevNet Always On Sandbox for IOS XE 4 | 5 | This is a shared sandbox available for anyone to use to 6 | test APIs, explore features, and test scripts. Please 7 | keep this in mind as you use it, and respect others use. 8 | 9 | The following programmability features are already enabled: 10 | - NETCONF 11 | - RESTCONF 12 | 13 | Thanks for stopping by. 14 | 15 | 16 | 17 | csr1000v#enable 18 | csr1000v#config t 19 | Enter configuration commands, one per line. End with CNTL/Z. 20 | csr1000v(config)#interface loopback 72 21 | csr1000v(config-if)#description golang test script 22 | csr1000v(config-if)#exit 23 | csr1000v(config)#exit 24 | csr1000v#show run interface loopback72 25 | Building configuration... 26 | 27 | Current configuration : 75 bytes 28 | ! 29 | interface Loopback72 30 | description golang test script 31 | no ip address 32 | end 33 | 34 | csr1000v# 35 | csr1000v#show ip int brief 36 | Interface IP-Address OK? Method Status Protocol 37 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 38 | GigabitEthernet2 unassigned YES NVRAM up up 39 | GigabitEthernet3 unassigned YES NVRAM administratively down down 40 | Loopback71 unassigned YES unset up up 41 | Loopback72 unassigned YES unset up up 42 | csr1000v#exit 43 | pi@raspberrypi:~/Coding_Folder $ 44 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_use_host_cmd_file_output_V2.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder $ go run ssh_use_host_cmd_files.go 2 | [ios-xe-mgmt-latest.cisco.com:8181 ios-xe-mgmt.cisco.com:8181] 3 | This is the config file named:ios-xe-mgmt-latest.cisco.com:8181.cfg 4 | 5 | 6 | 7 | 8 | 9 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 10 | 11 | The following programmability features are already enabled: 12 | - NETCONF 13 | - RESTCONF 14 | 15 | Thanks for stopping by. 16 | 17 | 18 | csr1000v-1#show interface description 19 | Interface Status Protocol Description 20 | Gi1 up up MANAGEMENT INTERFACE - DON'T TOUCH ME 21 | Gi2 admin down down Network Interface 22 | Gi3 admin down down Description set with Nornir 23 | Lo33 up up Created using RESTCONF from POSTMAN by HB 24 | Lo34 up up Configured using RESTCONF from postman 25 | Lo35 up up Created using RESTCONF from python by HB 26 | Lo37 up up Created using Netconf by python 27 | Lo39 up up Created using Netconf by python 28 | Lo77 up up MANAGEMENT INTERFACE - DON'T TOUCH ME 29 | Lo99 up up WHATEVER99 30 | Lo100 up up Network Interface 31 | csr1000v-1# 32 | csr1000v-1#config t 33 | Enter configuration commands, one per line. End with CNTL/Z. 34 | csr1000v-1(config)# 35 | csr1000v-1(config)#interface loopback 71 36 | csr1000v-1(config-if)# description Unique_configuration1 37 | csr1000v-1(config-if)# no shut 38 | csr1000v-1(config-if)#exit 39 | csr1000v-1(config)#exit 40 | csr1000v-1#! 41 | csr1000v-1#show interface description 42 | Interface Status Protocol Description 43 | Gi1 up up MANAGEMENT INTERFACE - DON'T TOUCH ME 44 | Gi2 admin down down Network Interface 45 | Gi3 admin down down Description set with Nornir 46 | Lo33 up up Created using RESTCONF from POSTMAN by HB 47 | Lo34 up up Configured using RESTCONF from postman 48 | Lo35 up up Created using RESTCONF from python by HB 49 | Lo37 up up Created using Netconf by python 50 | Lo39 up up Created using Netconf by python 51 | Lo71 up up Unique_configuration1 52 | Lo77 up up MANAGEMENT INTERFACE - DON'T TOUCH ME 53 | Lo99 up up WHATEVER99 54 | Lo100 up up Network Interface 55 | csr1000v-1#exit 56 | This is the config file named:ios-xe-mgmt.cisco.com:8181.cfg 57 | 58 | 59 | 60 | 61 | 62 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 63 | 64 | The following programmability features are already enabled: 65 | - NETCONF 66 | - RESTCONF 67 | 68 | Thanks for stopping by. 69 | 70 | 71 | csr1000v#show interface description 72 | Interface Status Protocol Description 73 | Gi1 up up MANAGEMENT INTERFACE - DON'T TOUCH ME 74 | Gi2 up up Configured by RESTCONF 75 | Gi3 admin down down Description set with Nornir 76 | Vi0 up up 77 | csr1000v# 78 | csr1000v#config t 79 | Enter configuration commands, one per line. End with CNTL/Z. 80 | csr1000v(config)#interface loopback 72 81 | csr1000v(config-if)# description Unique_config_number_2 82 | csr1000v(config-if)# no shut 83 | csr1000v(config-if)#exit 84 | csr1000v(config)#exit 85 | csr1000v#! 86 | csr1000v#show interface description 87 | Interface Status Protocol Description 88 | Gi1 up up MANAGEMENT INTERFACE - DON'T TOUCH ME 89 | Gi2 up up Configured by RESTCONF 90 | Gi3 admin down down Description set with Nornir 91 | Lo72 up up Unique_config_number_2 92 | Vi0 up up 93 | csr1000v# 94 | csr1000v# 95 | csr1000v# 96 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_use_host_cmd_files_V2.go: -------------------------------------------------------------------------------- 1 | // This ssh script will use host_file.txt to determine who to 2 | // login to, and the host.cfg file to determine which commands 3 | // to run on each device 4 | // (c) 2020 Todd Riemenschneider 5 | 6 | package main 7 | 8 | import ( 9 | "bufio" 10 | "fmt" 11 | "golang.org/x/crypto/ssh" 12 | "log" 13 | "os" 14 | "time" 15 | ) 16 | 17 | var hostList []string 18 | 19 | func loginHosts() { 20 | hf, _ := os.Open("host_file001.txt") 21 | scanner := bufio.NewScanner(hf) 22 | scanner.Split(bufio.ScanLines) 23 | for scanner.Scan() { 24 | hostList = append(hostList, scanner.Text()) 25 | } 26 | fmt.Println(hostList) 27 | } 28 | 29 | func main() { 30 | loginHosts() 31 | for _, host := range hostList { 32 | user := "developer" 33 | pass := "C1sco12345" 34 | targethost := host 35 | 36 | config := &ssh.ClientConfig{ 37 | User: user, 38 | Auth: []ssh.AuthMethod{ 39 | ssh.Password(pass), 40 | }, 41 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 42 | } 43 | 44 | conn, err := ssh.Dial("tcp", targethost, config) 45 | time.Sleep(1) 46 | //Used for troubleshooting 47 | //fmt.Println(conn) 48 | if err != nil { 49 | log.Fatal("Failed to dial: ", err) 50 | } 51 | sess, err := conn.NewSession() 52 | if err != nil { 53 | log.Fatal("Failed to create session: ", err) 54 | } 55 | stdin, err := sess.StdinPipe() 56 | sess.Stdout = os.Stdout 57 | sess.Stderr = os.Stderr 58 | sess.Shell() 59 | // cmds file should use host.cfg name standard 60 | fmt.Println("This is the config file named:" + host + ".cfg") 61 | fmt.Printf("\n\n\n\n") 62 | cmds, _ := os.Open(host + ".cfg") 63 | scanner := bufio.NewScanner(cmds) 64 | scanner.Split(bufio.ScanLines) 65 | var lines []string 66 | for scanner.Scan() { 67 | lines = append(lines, scanner.Text()) 68 | } 69 | cmds.Close() 70 | for _, line := range lines { 71 | fmt.Fprintf(stdin, "%s\n", line) 72 | } 73 | fmt.Fprintf(stdin, "exit\n") 74 | fmt.Fprintf(stdin, "exit\n") 75 | sess.Wait() 76 | sess.Close() 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_use_stdin.go: -------------------------------------------------------------------------------- 1 | // This ssh script will use standard input to push commands/configs to a Cisco IOS device 2 | // To run 'go run ssh_use_stdin.go < cmd_file.txt' 3 | // This functionality would allow you to use any commands file without having to rewrite commands file or script. 4 | // (c) 2019 Todd Riemenschneider 5 | 6 | package main 7 | 8 | import ( 9 | "bufio" 10 | "fmt" 11 | "golang.org/x/crypto/ssh" 12 | "log" 13 | "os" 14 | ) 15 | 16 | func main() { 17 | user := "root" 18 | pass := "D_Vay!_10&" 19 | targethost := "ios-xe-mgmt.cisco.com:8181" 20 | 21 | config := &ssh.ClientConfig{ 22 | User: user, 23 | Auth: []ssh.AuthMethod{ 24 | ssh.Password(pass), 25 | }, 26 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 27 | } 28 | conn, err := ssh.Dial("tcp", targethost, config) 29 | if err != nil { 30 | log.Fatal("Failed to dial: ", err) 31 | } 32 | sess, err := conn.NewSession() 33 | if err != nil { 34 | log.Fatal("Failed to create session: ", err) 35 | } 36 | stdin, _ := sess.StdinPipe() 37 | sess.Stdout = os.Stdout 38 | sess.Stderr = os.Stderr 39 | sess.Shell() 40 | // Below are the lines of code that will allow stdin to push cmds 41 | scanner := bufio.NewScanner(os.Stdin) 42 | scanner.Split(bufio.ScanLines) 43 | var lines []string 44 | for scanner.Scan() { 45 | lines = append(lines, scanner.Text()) 46 | } 47 | for _, line := range lines { 48 | fmt.Fprintf(stdin, "%s\n", line) 49 | } 50 | // End of code for this functionality 51 | sess.Wait() 52 | sess.Close() 53 | 54 | } 55 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_use_stdin_output.txt: -------------------------------------------------------------------------------- 1 | pi@raspberrypi:~/Coding_Folder $ go run ssh_use_stdin.go < cmd_file.txt 2 | 3 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 4 | 5 | The following programmability features are already enabled: 6 | - NETCONF 7 | - RESTCONF 8 | 9 | Thanks for stopping by. 10 | 11 | 12 | 13 | csr1000v#enable 14 | csr1000v#terminal length 0 15 | csr1000v#config t 16 | Enter configuration commands, one per line. End with CNTL/Z. 17 | csr1000v(config)#interface loopback 71 18 | csr1000v(config-if)# description golang_script_test 19 | csr1000v(config-if)#interface loopback 72 20 | csr1000v(config-if)# description golang_script_test 21 | csr1000v(config-if)# exit 22 | csr1000v(config)# exit 23 | csr1000v#show ip int brief 24 | Interface IP-Address OK? Method Status Protocol 25 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 26 | GigabitEthernet2 172.16.255.1 YES other up up 27 | GigabitEthernet3 unassigned YES NVRAM administratively down down 28 | Loopback71 unassigned YES unset up up 29 | Loopback72 unassigned YES unset up up 30 | csr1000v#show version 31 | Cisco IOS XE Software, Version 16.09.03 32 | Cisco IOS Software [Fuji], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.9.3, RELEASE SOFTWARE (fc2) 33 | Technical Support: http://www.cisco.com/techsupport 34 | Copyright (c) 1986-2019 by Cisco Systems, Inc. 35 | Compiled Wed 20-Mar-19 07:56 by mcpre 36 | 37 | 38 | Cisco IOS-XE software, Copyright (c) 2005-2019 by cisco Systems, Inc. 39 | All rights reserved. Certain components of Cisco IOS-XE software are 40 | licensed under the GNU General Public License ("GPL") Version 2.0. The 41 | software code licensed under GPL Version 2.0 is free software that comes 42 | with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such 43 | GPL code under the terms of GPL Version 2.0. For more details, see the 44 | documentation or "License Notice" file accompanying the IOS-XE software, 45 | or the applicable URL provided on the flyer accompanying the IOS-XE 46 | software. 47 | 48 | 49 | ROM: IOS-XE ROMMON 50 | 51 | csr1000v uptime is 10 hours, 0 minutes 52 | Uptime for this control processor is 10 hours, 2 minutes 53 | System returned to ROM by reload 54 | System image file is "bootflash:packages.conf" 55 | Last reload reason: reload 56 | 57 | 58 | 59 | This product contains cryptographic features and is subject to United 60 | States and local country laws governing import, export, transfer and 61 | use. Delivery of Cisco cryptographic products does not imply 62 | third-party authority to import, export, distribute or use encryption. 63 | Importers, exporters, distributors and users are responsible for 64 | compliance with U.S. and local country laws. By using this product you 65 | agree to comply with applicable laws and regulations. If you are unable 66 | to comply with U.S. and local laws, return this product immediately. 67 | 68 | A summary of U.S. laws governing Cisco cryptographic products may be found at: 69 | http://www.cisco.com/wwl/export/crypto/tool/stqrg.html 70 | 71 | If you require further assistance please contact us by sending email to 72 | export@cisco.com. 73 | 74 | License Level: ax 75 | License Type: Default. No valid license found. 76 | Next reload license Level: ax 77 | 78 | 79 | Smart Licensing Status: Smart Licensing is DISABLED 80 | 81 | cisco CSR1000V (VXE) processor (revision VXE) with 2392579K/3075K bytes of memory. 82 | Processor board ID 9G44U15Y0XH 83 | 3 Gigabit Ethernet interfaces 84 | 32768K bytes of non-volatile configuration memory. 85 | 8113280K bytes of physical memory. 86 | 7774207K bytes of virtual hard disk at bootflash:. 87 | 0K bytes of WebUI ODM Files at webui:. 88 | 89 | Configuration register is 0x2102 90 | 91 | csr1000v#show run all | inc ssh 92 | netconf-yang ssh port 830 93 | ip ssh time-out 120 94 | ip ssh authentication-retries 3 95 | ip ssh window-size 8192 96 | ip ssh rsa keypair-name ssh-key 97 | ip ssh break-string ~break 98 | ip ssh version 2 99 | ip ssh dh min size 2048 100 | no ip ssh rekey time 101 | no ip ssh rekey volume 102 | ip ssh server authenticate user publickey 103 | ip ssh server authenticate user keyboard 104 | ip ssh server authenticate user password 105 | no ip ssh server peruser session limit 106 | ip ssh server certificate profile 107 | ip ssh server algorithm mac hmac-sha2-256 hmac-sha2-512 hmac-sha1 hmac-sha1-96 108 | ip ssh server algorithm encryption aes128-ctr aes192-ctr aes256-ctr 109 | ip ssh server algorithm kex diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 110 | ip ssh server algorithm hostkey x509v3-ssh-rsa ssh-rsa 111 | ip ssh server algorithm authentication publickey keyboard password 112 | ip ssh server algorithm publickey x509v3-ssh-rsa ssh-rsa 113 | ip ssh client algorithm mac hmac-sha2-256 hmac-sha2-512 hmac-sha1 hmac-sha1-96 114 | ip ssh client algorithm encryption aes128-ctr aes192-ctr aes256-ctr 115 | ip ssh client algorithm kex diffie-hellman-group-exchange-sha1 diffie-hellman-group14-sha1 116 | transport input ssh 117 | no transport type persistent ssh input 118 | csr1000v#exit 119 | pi@raspberrypi:~/Coding_Folder $ 120 | 121 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_use_stdin_output_2.txt: -------------------------------------------------------------------------------- 1 | pi@raspberrypi:~/Coding_Folder $ go run ssh_use_stdin.go < cmd_file2.txt 2 | 3 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 4 | 5 | The following programmability features are already enabled: 6 | - NETCONF 7 | - RESTCONF 8 | 9 | Thanks for stopping by. 10 | 11 | 12 | 13 | csr1000v#enable 14 | csr1000v#show ip route 15 | Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP 16 | D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 17 | N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 18 | E1 - OSPF external type 1, E2 - OSPF external type 2 19 | i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 20 | ia - IS-IS inter area, * - candidate default, U - per-user static route 21 | o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP 22 | a - application route 23 | + - replicated route, % - next hop override, p - overrides from PfR 24 | 25 | Gateway of last resort is 10.10.20.254 to network 0.0.0.0 26 | 27 | S* 0.0.0.0/0 [1/0] via 10.10.20.254, GigabitEthernet1 28 | 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks 29 | C 10.10.20.0/24 is directly connected, GigabitEthernet1 30 | L 10.10.20.48/32 is directly connected, GigabitEthernet1 31 | 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks 32 | C 172.16.255.0/24 is directly connected, GigabitEthernet2 33 | L 172.16.255.1/32 is directly connected, GigabitEthernet2 34 | csr1000v#show version | inc IOS 35 | Cisco IOS XE Software, Version 16.09.03 36 | Cisco IOS Software [Fuji], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.9.3, RELEASE SOFTWARE (fc2) 37 | Cisco IOS-XE software, Copyright (c) 2005-2019 by cisco Systems, Inc. 38 | All rights reserved. Certain components of Cisco IOS-XE software are 39 | documentation or "License Notice" file accompanying the IOS-XE software, 40 | or the applicable URL provided on the flyer accompanying the IOS-XE 41 | ROM: IOS-XE ROMMON 42 | csr1000v#exit 43 | pi@raspberrypi:~/Coding_Folder $ 44 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_using_cli_args.go: -------------------------------------------------------------------------------- 1 | // This is a user interactive ssh script 2 | // You will enter the commands to run at the time you run the script 3 | // (c) 2020 Todd Riemenschneider 4 | 5 | package main 6 | 7 | import ( 8 | "fmt" 9 | "golang.org/x/crypto/ssh" 10 | "log" 11 | "os" 12 | "strings" 13 | ) 14 | 15 | func main() { 16 | user := "developer" 17 | pass := "C1sco12345" 18 | targethost := "ios-xe-mgmt-latest.cisco.com:8181" 19 | 20 | cmdString := strings.Join(os.Args[1:], " ") 21 | fmt.Println("Commands being run :", cmdString) 22 | cmds := strings.Split(cmdString, ",") 23 | 24 | config := &ssh.ClientConfig{ 25 | User: user, 26 | Auth: []ssh.AuthMethod{ 27 | ssh.Password(pass), 28 | }, 29 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 30 | } 31 | conn, err := ssh.Dial("tcp", targethost, config) 32 | if err != nil { 33 | log.Fatal("Failed to dial: ", err) 34 | } 35 | sess, err := conn.NewSession() 36 | if err != nil { 37 | log.Fatal("Failed to create session: ", err) 38 | } 39 | stdin, _ := sess.StdinPipe() 40 | sess.Stdout = os.Stdout 41 | sess.Stderr = os.Stderr 42 | sess.Shell() 43 | fmt.Fprintf(stdin, "term len 0\n") 44 | for _, cmd := range cmds { 45 | fmt.Fprintf(stdin, "%s\n", cmd) 46 | } 47 | fmt.Fprintf(stdin, "exit\n") 48 | fmt.Fprintf(stdin, "exit\n") 49 | sess.Wait() 50 | sess.Close() 51 | } 52 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_using_cli_args_output.txt: -------------------------------------------------------------------------------- 1 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder $ go run ssh_using_cli_args.go show ip int brief, "show version | inc IOS", show int description 2 | Commands being run : show ip int brief, show version | inc IOS, show int description 3 | 4 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 5 | 6 | The following programmability features are already enabled: 7 | - NETCONF 8 | - RESTCONF 9 | 10 | Thanks for stopping by. 11 | 12 | 13 | 14 | csr1000v-1#term len 0 15 | csr1000v-1#show ip int brief 16 | Interface IP-Address OK? Method Status Protocol 17 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 18 | GigabitEthernet2 unassigned YES NVRAM administratively down down 19 | GigabitEthernet3 unassigned YES NVRAM administratively down down 20 | csr1000v-1# show version | inc IOS 21 | Cisco IOS XE Software, Version 16.11.01a 22 | Cisco IOS Software [Gibraltar], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.11.1a, RELEASE SOFTWARE (fc1) 23 | Cisco IOS-XE software, Copyright (c) 2005-2019 by cisco Systems, Inc. 24 | All rights reserved. Certain components of Cisco IOS-XE software are 25 | documentation or "License Notice" file accompanying the IOS-XE software, 26 | or the applicable URL provided on the flyer accompanying the IOS-XE 27 | ROM: IOS-XE ROMMON 28 | csr1000v-1# show int description 29 | Interface Status Protocol Description 30 | Gi1 up up MANAGEMENT INTERFACE - DON'T TOUCH ME 31 | Gi2 admin down down Network Interface 32 | Gi3 admin down down Network Interface 33 | csr1000v-1#exit 34 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder $ 35 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_using_host_cmd_files.go: -------------------------------------------------------------------------------- 1 | // This ssh script will use host_file.txt to determine who to 2 | // login to, and the cmd_file1.txt to determine which commands 3 | // to run. 4 | // (c) 2019 Todd Riemenschneider 5 | 6 | package main 7 | 8 | import ( 9 | "bufio" 10 | "fmt" 11 | "golang.org/x/crypto/ssh" 12 | "log" 13 | "os" 14 | ) 15 | 16 | var hostList []string 17 | 18 | func loginHosts() { 19 | hf, _ := os.Open("host_file001.txt") 20 | scanner := bufio.NewScanner(hf) 21 | scanner.Split(bufio.ScanLines) 22 | for scanner.Scan() { 23 | hostList = append(hostList, scanner.Text()) 24 | // scaffolding for troubleshooting 25 | // fmt.Println(hostList) 26 | } 27 | } 28 | func main() { 29 | loginHosts() 30 | //scaffolding for troubleshooting 31 | //for _, host := range hostList { 32 | // fmt.Println(host) 33 | for _, host := range hostList { 34 | user := "developer" 35 | pass := "C1sco12345" 36 | targethost := host 37 | 38 | config := &ssh.ClientConfig{ 39 | User: user, 40 | Auth: []ssh.AuthMethod{ 41 | ssh.Password(pass), 42 | }, 43 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 44 | } 45 | conn, err := ssh.Dial("tcp", targethost, config) 46 | //Scaffolding for troubleshooting 47 | //fmt.Println(conn) 48 | if err != nil { 49 | log.Fatal("Failed to dial: ", err) 50 | } 51 | sess, err := conn.NewSession() 52 | if err != nil { 53 | log.Fatal("Failed to create session: ", err) 54 | } 55 | stdin, _ := sess.StdinPipe() 56 | sess.Stdout = os.Stdout 57 | sess.Stderr = os.Stderr 58 | sess.Shell() 59 | cmds, _ := os.Open("cmd_file001.txt") 60 | scanner := bufio.NewScanner(cmds) 61 | scanner.Split(bufio.ScanLines) 62 | var lines []string 63 | for scanner.Scan() { 64 | lines = append(lines, scanner.Text()) 65 | } 66 | cmds.Close() 67 | for _, line := range lines { 68 | fmt.Fprintf(stdin, "%s\n", line) 69 | } 70 | sess.Wait() 71 | sess.Close() 72 | } 73 | } 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /ssh_client/pre_go.mod_stuff/ssh_using_host_cmd_files_output.txt: -------------------------------------------------------------------------------- 1 | pi@raspberrypi:~/Code_folder/go_folder/netOps $ go run ssh_using_host_cmd_files.go 2 | 3 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 4 | 5 | The following programmability features are already enabled: 6 | - NETCONF 7 | - RESTCONF 8 | 9 | Thanks for stopping by. 10 | 11 | 12 | 13 | csr1000v-1#enable 14 | csr1000v-1#term len 0 15 | csr1000v-1#config t 16 | Enter configuration commands, one per line. End with CNTL/Z. 17 | csr1000v-1(config)#interface loopback 72 18 | csr1000v-1(config-if)#description testing go_ssh 19 | csr1000v-1(config-if)#exit 20 | csr1000v-1(config)#exit 21 | csr1000v-1#show run int loopback 72 22 | Building configuration... 23 | 24 | Current configuration : 71 bytes 25 | ! 26 | interface Loopback72 27 | description testing go_ssh 28 | no ip address 29 | end 30 | 31 | csr1000v-1#config t 32 | Enter configuration commands, one per line. End with CNTL/Z. 33 | csr1000v-1(config)#interface loopback71 34 | csr1000v-1(config-if)#description testing go_ssh 35 | csr1000v-1(config-if)#exit 36 | csr1000v-1(config)#exit 37 | csr1000v-1#sh run int loopback 71 38 | Building configuration... 39 | 40 | Current configuration : 71 bytes 41 | ! 42 | interface Loopback71 43 | description testing go_ssh 44 | no ip address 45 | end 46 | 47 | csr1000v-1# 48 | csr1000v-1#show ip int brief 49 | Interface IP-Address OK? Method Status Protocol 50 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 51 | GigabitEthernet2 unassigned YES NVRAM administratively down down 52 | GigabitEthernet3 unassigned YES NVRAM administratively down down 53 | Loopback22 unassigned YES unset up up 54 | Loopback71 unassigned YES unset up up 55 | Loopback72 unassigned YES unset up up 56 | Loopback803 unassigned YES unset up up 57 | csr1000v-1#show ip route summ 58 | IP routing table name is default (0x0) 59 | IP routing table maximum-paths is 32 60 | Route Source Networks Subnets Replicates Overhead Memory (bytes) 61 | application 0 0 0 0 0 62 | connected 0 2 0 192 624 63 | static 1 0 0 96 312 64 | internal 1 632 65 | Total 2 2 0 288 1568 66 | csr1000v-1#show cdp neighbor 67 | Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge 68 | S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone, 69 | D - Remote, C - CVTA, M - Two-port Mac Relay 70 | 71 | Device ID Local Intrfce Holdtme Capability Platform Port ID 72 | 73 | Total cdp entries displayed : 0 74 | csr1000v-1#show arp 75 | Protocol Address Age (min) Hardware Addr Type Interface 76 | Internet 10.10.20.48 - 0050.56bb.e99c ARPA GigabitEthernet1 77 | Internet 10.10.20.200 14 0050.56bb.8be2 ARPA GigabitEthernet1 78 | Internet 10.10.20.254 0 0896.ad9e.444c ARPA GigabitEthernet1 79 | csr1000v-1#show version 80 | Cisco IOS XE Software, Version 16.11.01a 81 | Cisco IOS Software [Gibraltar], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.11.1a, RELEASE SOFTWARE (fc1) 82 | Technical Support: http://www.cisco.com/techsupport 83 | Copyright (c) 1986-2019 by Cisco Systems, Inc. 84 | Compiled Thu 11-Apr-19 23:59 by mcpre 85 | 86 | 87 | Cisco IOS-XE software, Copyright (c) 2005-2019 by cisco Systems, Inc. 88 | All rights reserved. Certain components of Cisco IOS-XE software are 89 | licensed under the GNU General Public License ("GPL") Version 2.0. The 90 | software code licensed under GPL Version 2.0 is free software that comes 91 | with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such 92 | GPL code under the terms of GPL Version 2.0. For more details, see the 93 | documentation or "License Notice" file accompanying the IOS-XE software, 94 | or the applicable URL provided on the flyer accompanying the IOS-XE 95 | software. 96 | 97 | 98 | ROM: IOS-XE ROMMON 99 | 100 | csr1000v-1 uptime is 5 days, 12 hours, 5 minutes 101 | Uptime for this control processor is 5 days, 12 hours, 6 minutes 102 | System returned to ROM by reload 103 | System image file is "bootflash:packages.conf" 104 | Last reload reason: reload 105 | 106 | 107 | 108 | This product contains cryptographic features and is subject to United 109 | States and local country laws governing import, export, transfer and 110 | use. Delivery of Cisco cryptographic products does not imply 111 | third-party authority to import, export, distribute or use encryption. 112 | Importers, exporters, distributors and users are responsible for 113 | compliance with U.S. and local country laws. By using this product you 114 | agree to comply with applicable laws and regulations. If you are unable 115 | to comply with U.S. and local laws, return this product immediately. 116 | 117 | A summary of U.S. laws governing Cisco cryptographic products may be found at: 118 | http://www.cisco.com/wwl/export/crypto/tool/stqrg.html 119 | 120 | If you require further assistance please contact us by sending email to 121 | export@cisco.com. 122 | 123 | License Level: ax 124 | License Type: N/A(Smart License Enabled) 125 | Next reload license Level: ax 126 | 127 | 128 | Smart Licensing Status: UNREGISTERED/No Licenses in Use 129 | 130 | cisco CSR1000V (VXE) processor (revision VXE) with 2378575K/3075K bytes of memory. 131 | Processor board ID 989DIA2RYVT 132 | 3 Gigabit Ethernet interfaces 133 | 32768K bytes of non-volatile configuration memory. 134 | 8112832K bytes of physical memory. 135 | 7774207K bytes of virtual hard disk at bootflash:. 136 | 0K bytes of WebUI ODM Files at webui:. 137 | 138 | Configuration register is 0x2102 139 | 140 | csr1000v-1#exit 141 | 142 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 143 | 144 | The following programmability features are already enabled: 145 | - NETCONF 146 | - RESTCONF 147 | 148 | Thanks for stopping by. 149 | 150 | 151 | csr1000v-1#enable 152 | csr1000v-1#term len 0 153 | csr1000v-1#config t 154 | Enter configuration commands, one per line. End with CNTL/Z. 155 | csr1000v-1(config)#interface loopback 72 156 | csr1000v-1(config-if)#description testing go_ssh 157 | csr1000v-1(config-if)#exit 158 | csr1000v-1(config)#exit 159 | csr1000v-1#show run int loopback 72 160 | Building configuration... 161 | 162 | Current configuration : 71 bytes 163 | ! 164 | interface Loopback72 165 | description testing go_ssh 166 | no ip address 167 | end 168 | 169 | csr1000v-1#config t 170 | Enter configuration commands, one per line. End with CNTL/Z. 171 | csr1000v-1(config)#interface loopback71 172 | csr1000v-1(config-if)#description testing go_ssh 173 | csr1000v-1(config-if)#exit 174 | csr1000v-1(config)#exit 175 | csr1000v-1#sh run int loopback 71 176 | Building configuration... 177 | 178 | Current configuration : 71 bytes 179 | ! 180 | interface Loopback71 181 | description testing go_ssh 182 | no ip address 183 | end 184 | 185 | csr1000v-1# 186 | csr1000v-1#show ip int brief 187 | Interface IP-Address OK? Method Status Protocol 188 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 189 | GigabitEthernet2 unassigned YES NVRAM administratively down down 190 | GigabitEthernet3 unassigned YES NVRAM administratively down down 191 | Loopback22 unassigned YES unset up up 192 | Loopback71 unassigned YES unset up up 193 | Loopback72 unassigned YES unset up up 194 | Loopback803 unassigned YES unset up up 195 | csr1000v-1#show ip route summ 196 | IP routing table name is default (0x0) 197 | IP routing table maximum-paths is 32 198 | Route Source Networks Subnets Replicates Overhead Memory (bytes) 199 | application 0 0 0 0 0 200 | connected 0 2 0 192 624 201 | static 1 0 0 96 312 202 | internal 1 632 203 | Total 2 2 0 288 1568 204 | csr1000v-1#show cdp neighbor 205 | Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge 206 | S - Switch, H - Host, I - IGMP, r - Repeater, P - Phone, 207 | D - Remote, C - CVTA, M - Two-port Mac Relay 208 | 209 | Device ID Local Intrfce Holdtme Capability Platform Port ID 210 | 211 | Total cdp entries displayed : 0 212 | csr1000v-1#show arp 213 | Protocol Address Age (min) Hardware Addr Type Interface 214 | Internet 10.10.20.48 - 0050.56bb.e99c ARPA GigabitEthernet1 215 | Internet 10.10.20.200 14 0050.56bb.8be2 ARPA GigabitEthernet1 216 | Internet 10.10.20.254 0 0896.ad9e.444c ARPA GigabitEthernet1 217 | csr1000v-1#show version 218 | Cisco IOS XE Software, Version 16.11.01a 219 | Cisco IOS Software [Gibraltar], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.11.1a, RELEASE SOFTWARE (fc1) 220 | Technical Support: http://www.cisco.com/techsupport 221 | Copyright (c) 1986-2019 by Cisco Systems, Inc. 222 | Compiled Thu 11-Apr-19 23:59 by mcpre 223 | 224 | 225 | Cisco IOS-XE software, Copyright (c) 2005-2019 by cisco Systems, Inc. 226 | All rights reserved. Certain components of Cisco IOS-XE software are 227 | licensed under the GNU General Public License ("GPL") Version 2.0. The 228 | software code licensed under GPL Version 2.0 is free software that comes 229 | with ABSOLUTELY NO WARRANTY. You can redistribute and/or modify such 230 | GPL code under the terms of GPL Version 2.0. For more details, see the 231 | documentation or "License Notice" file accompanying the IOS-XE software, 232 | or the applicable URL provided on the flyer accompanying the IOS-XE 233 | software. 234 | 235 | 236 | ROM: IOS-XE ROMMON 237 | 238 | csr1000v-1 uptime is 5 days, 12 hours, 5 minutes 239 | Uptime for this control processor is 5 days, 12 hours, 6 minutes 240 | System returned to ROM by reload 241 | System image file is "bootflash:packages.conf" 242 | Last reload reason: reload 243 | 244 | 245 | 246 | This product contains cryptographic features and is subject to United 247 | States and local country laws governing import, export, transfer and 248 | use. Delivery of Cisco cryptographic products does not imply 249 | third-party authority to import, export, distribute or use encryption. 250 | Importers, exporters, distributors and users are responsible for 251 | compliance with U.S. and local country laws. By using this product you 252 | agree to comply with applicable laws and regulations. If you are unable 253 | to comply with U.S. and local laws, return this product immediately. 254 | 255 | A summary of U.S. laws governing Cisco cryptographic products may be found at: 256 | http://www.cisco.com/wwl/export/crypto/tool/stqrg.html 257 | 258 | If you require further assistance please contact us by sending email to 259 | export@cisco.com. 260 | 261 | License Level: ax 262 | License Type: N/A(Smart License Enabled) 263 | Next reload license Level: ax 264 | 265 | 266 | Smart Licensing Status: UNREGISTERED/No Licenses in Use 267 | 268 | cisco CSR1000V (VXE) processor (revision VXE) with 2378575K/3075K bytes of memory. 269 | Processor board ID 989DIA2RYVT 270 | 3 Gigabit Ethernet interfaces 271 | 32768K bytes of non-volatile configuration memory. 272 | 8112832K bytes of physical memory. 273 | 7774207K bytes of virtual hard disk at bootflash:. 274 | 0K bytes of WebUI ODM Files at webui:. 275 | 276 | Configuration register is 0x2102 277 | 278 | csr1000v-1#exit 279 | pi@raspberrypi:~/Code_folder/go_folder/netOps $ 280 | -------------------------------------------------------------------------------- /ssh_client/runcli/README.md: -------------------------------------------------------------------------------- 1 | # runcli 2 | 3 | The idea behind this code is that you could quickly gather info on the fly as well as make minor changes if so desired. 4 | When you import this package into your code it will ask you how many devices you want to connect to, as well as what commands you want to run. 5 | The code will work with show commands as well as configuration commands. Good gathering info and for minor changes especially in a lab environment. 6 | 7 | Once you've downloaded package you need to make sure your GOROOT knows where to find it. 8 | 9 | I found installing the file from a third party system (Repl.it) was giving me some grief using go.mods. Go figure. It stated "You declared mod as: x but was required as url/xyz/x". After looking through some google searched I decided to remove the go.mod file from the directory and simply issue a go get to install the package. The old school way, and it worked. 10 | 11 | # To install 12 | 13 | ``` 14 |  go get github.com/twr14152/Go_Network_Scripts/ssh_client/runcli 15 | 16 | ``` 17 | 18 | In this example we have 3 devices 2 ios-xe and 1 nx-os. The login parameters for the ios-xe are the same and the nxos is different. The app will then prompt you to enter the commands you want. In your code all you will need to do is import "runcli" and add your login credentials to runcli.RunCli() for each group. The app will then prompt you for the commands to run. 19 | 20 | Sample code: 21 | 22 | Created file main.go and added the following: 23 | ``` 24 | package main 25 | 26 | import ( 27 | "fmt" 28 | "github.com/twr14152/Go_Network_Scripts/ssh_client/runcli" 29 | ) 30 | 31 | func main() { 32 | fmt.Println("Connecting to ios-xe devices:") 33 | runcli.RunCli("username1", "password1") 34 | fmt.Println("\n\n\nConnecting to nxos device:") 35 | runcli.RunCli("username2", "password2") 36 | } 37 | ``` 38 | The one thing you will need to do when you get prompted is to provide the hostname with the port your connecting on. 39 | 40 | For example: 41 | ``` 42 | host1:22 43 | 44 | host2:8181 45 | 46 | ``` 47 | 48 | # Running code with show commands 49 | 50 | Remember when you give the host device to add the port your connecting on. 51 | 52 | ``` 53 | $ go run main.go 54 | Connecting to ios-xe devices: 55 | Number of hosts: 2 56 | Hostname: fastxe:22 57 | 58 | cmds: show ip int brief 59 | 60 | Hostname: slowxe:8181 61 | 62 | cmds: show ip int brief 63 | 64 | 65 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 66 | 67 | The following programmability features are already enabled: 68 | - NETCONF 69 | - RESTCONF 70 | 71 | Thanks for stopping by. 72 | 73 | 74 | csr1000v-1#term len 0 75 | csr1000v-1#show ip int brief 76 | Interface IP-Address OK? Method Status Protocol 77 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 78 | GigabitEthernet2 unassigned YES NVRAM administratively down down 79 | GigabitEthernet3 unassigned YES NVRAM administratively down down 80 | Loopback0 100.64.0.1 YES other up up 81 | Loopback300 unassigned YES unset up up 82 | Loopback444 unassigned YES unset up up 83 | VirtualPortGroup0 192.168.35.1 YES manual up up 84 | csr1000v-1# 85 | csr1000v-1#exit 86 | 87 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 88 | 89 | The following programmability features are already enabled: 90 | - NETCONF 91 | - RESTCONF 92 | 93 | Thanks for stopping by. 94 | 95 | 96 | 97 | csr1000v#term len 0 98 | csr1000v#show ip int brief 99 | Interface IP-Address OK? Method Status Protocol 100 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 101 | GigabitEthernet2 unassigned YES NVRAM administratively down down 102 | GigabitEthernet3 unassigned YES NVRAM administratively down down 103 | csr1000v# 104 | csr1000v#exit 105 | 106 | 107 | 108 | Connecting to nxos device: 109 | Number of hosts: 1 110 | Hostname: nxos:8181 111 | 112 | cmds: show ip int brief 113 | 114 | 115 | stty: standard input: Inappropriate ioctl for device 116 | gl_set_term_size: NULL arguments(s). 117 | 118 | IP Interface Status for VRF "default"(1) 119 | Interface IP Address Interface Status 120 | Vlan100 172.16.100.1 protocol-up/link-up/admin-up 121 | Vlan101 172.16.101.1 protocol-down/link-down/admin-down 122 | Vlan102 172.16.102.1 protocol-down/link-down/admin-down 123 | Vlan103 172.16.103.1 protocol-down/link-down/admin-down 124 | Vlan104 172.16.104.1 protocol-down/link-down/admin-down 125 | Vlan105 172.16.105.1 protocol-down/link-down/admin-down 126 | Lo1 172.16.0.1 protocol-up/link-up/admin-up 127 | Lo98 10.98.98.1 protocol-up/link-up/admin-up 128 | Lo99 10.99.99.1 protocol-up/link-up/admin-up 129 | Eth1/5 172.16.1.1 protocol-down/link-down/admin-down 130 | $ 131 | ``` 132 | 133 | 134 | # Running code with configuration commands + validation commands. 135 | 136 | Using the same main.go file we will add loopback75 to fastxe csr and loopback76 to nxos device. 137 | 138 | ``` 139 | $ go run main.go 140 | Connecting to ios-xe devices: 141 | Number of hosts: 1 142 | Hostname: fastxe:22 143 | 144 | cmds: config t, interface loopback75, ip address 75.0.0.1 255.255.255.255, description go script test, exit, exit, show ip int brief, show run int loopback75 145 | 146 | 147 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 148 | 149 | The following programmability features are already enabled: 150 | - NETCONF 151 | - RESTCONF 152 | 153 | Thanks for stopping by. 154 | 155 | 156 | 157 | csr1000v-1#term len 0 158 | csr1000v-1#config t 159 | Enter configuration commands, one per line. End with CNTL/Z. 160 | csr1000v-1(config)# interface loopback75 161 | csr1000v-1(config-if)# ip address 75.0.0.1 255.255.255.255 162 | csr1000v-1(config-if)# description go script test 163 | csr1000v-1(config-if)# exit 164 | csr1000v-1(config)# exit 165 | csr1000v-1# show ip int brief 166 | Interface IP-Address OK? Method Status Protocol 167 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 168 | GigabitEthernet2 unassigned YES NVRAM administratively down down 169 | GigabitEthernet3 unassigned YES NVRAM administratively down down 170 | Loopback0 100.64.0.1 YES other up up 171 | Loopback75 75.0.0.1 YES manual up up 172 | Loopback300 unassigned YES unset up up 173 | Loopback444 unassigned YES unset up up 174 | VirtualPortGroup0 192.168.35.1 YES manual up up 175 | csr1000v-1# show run int loopback75 176 | Building configuration... 177 | 178 | Current configuration : 93 bytes 179 | ! 180 | interface Loopback75 181 | description go script test 182 | ip address 75.0.0.1 255.255.255.255 183 | end 184 | 185 | csr1000v-1# 186 | csr1000v-1#exit 187 | 188 | 189 | 190 | Connecting to nxos device: 191 | Number of hosts: 1 192 | Hostname: nxos:8181 193 | 194 | cmds: config t, interface loopback76, ip address 76.0.0.1/32, description go script test, exit, exit, show ip int brief, show run int loopback76 195 | 196 | stty: standard input: Inappropriate ioctl for device 197 | 198 | gl_set_term_size: NULL arguments(s). 199 | 200 | IP Interface Status for VRF "default"(1) 201 | Interface IP Address Interface Status 202 | Vlan100 172.16.100.1 protocol-up/link-up/admin-up 203 | Vlan101 172.16.101.1 protocol-down/link-down/admin-down 204 | Vlan102 172.16.102.1 protocol-down/link-down/admin-down 205 | Vlan103 172.16.103.1 protocol-down/link-down/admin-down 206 | Vlan104 172.16.104.1 protocol-down/link-down/admin-down 207 | Vlan105 172.16.105.1 protocol-down/link-down/admin-down 208 | Lo1 172.16.0.1 protocol-up/link-up/admin-up 209 | Lo76 76.0.0.1 protocol-up/link-up/admin-up 210 | Lo98 10.98.98.1 protocol-up/link-up/admin-up 211 | Lo99 10.99.99.1 protocol-up/link-up/admin-up 212 | Eth1/5 172.16.1.1 protocol-down/link-down/admin-down 213 | 214 | !Command: show running-config interface loopback76 215 | !Running configuration last done at: Wed Dec 9 01:08:25 2020 216 | !Time: Wed Dec 9 01:08:25 2020 217 | 218 | version 9.3(3) Bios:version 219 | 220 | interface loopback76 221 | description go script test 222 | ip address 76.0.0.1/32 223 | 224 | $ 225 | 226 | ``` 227 | 228 | -------------------------------------------------------------------------------- /ssh_client/runcli/go.mod: -------------------------------------------------------------------------------- 1 | module runcli 2 | 3 | go 1.15 4 | 5 | require golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 6 | -------------------------------------------------------------------------------- /ssh_client/runcli/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 2 | golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 h1:sYNJzB4J8toYPQTM6pAkcmBRgw9SnQKP9oXCHfgy604= 3 | golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= 4 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 5 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 6 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= 7 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 8 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 9 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 10 | -------------------------------------------------------------------------------- /ssh_client/runcli/runcli.go: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2020 Todd Riemenschneider 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package runcli 26 | 27 | import ( 28 | "bufio" 29 | "fmt" 30 | "golang.org/x/crypto/ssh" 31 | "log" 32 | "os" 33 | "strings" 34 | ) 35 | 36 | func commands() map[string][]string { 37 | var count int 38 | var host string 39 | fmt.Print("Number of hosts: ") 40 | fmt.Scanf("%d", &count) 41 | hostCmds := make(map[string][]string) 42 | for i := 1; i <= count; i++ { 43 | fmt.Print("Hostname: ") 44 | fmt.Scanf("%s", &host) 45 | fmt.Println() 46 | reader := bufio.NewReader(os.Stdin) 47 | fmt.Print("cmds: ") 48 | cmds, _ := reader.ReadString('\n') 49 | s := strings.Split(cmds, ",") 50 | fmt.Println() 51 | hostCmds[host] = s 52 | } 53 | return hostCmds 54 | } 55 | 56 | func RunCli(user, pass string) { 57 | 58 | hostData := commands() 59 | 60 | for host, commands := range hostData { 61 | config := &ssh.ClientConfig{ 62 | User: user, 63 | Auth: []ssh.AuthMethod{ 64 | ssh.Password(pass), 65 | }, 66 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 67 | } 68 | conn, err := ssh.Dial("tcp", host, config) 69 | if err != nil { 70 | log.Fatal("Failed to dial: ", err) 71 | } 72 | sess, err := conn.NewSession() 73 | if err != nil { 74 | log.Fatal("Failed to create session: ", err) 75 | } 76 | stdin, _ := sess.StdinPipe() 77 | sess.Stdout = os.Stdout 78 | sess.Stderr = os.Stderr 79 | sess.Shell() 80 | fmt.Fprintf(stdin, "term len 0\n") 81 | for _, v := range commands { 82 | fmt.Fprintf(stdin, "%s\n", v) 83 | } 84 | fmt.Fprintf(stdin, "exit\n") 85 | fmt.Fprintf(stdin, "exit\n") 86 | sess.Wait() 87 | sess.Close() 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /ssh_client/runscript/README.md: -------------------------------------------------------------------------------- 1 | # runscript 2 | The goal of this package is to allow the user use host and cmd files to change and validate device configuration. 3 | You will simply need to import runscript into your main.go file and call the runscript.Connect() to connect to you devices. 4 | All you will need is the username password and the name of the hostfile you create with those common login parameters. 5 | If you have multiple login parameters create multiple hostfiles grouping those with common parameters. 6 | 7 | To install: 8 | ``` 9 | go get github.com/twr14152/Go_Network_Scripts/ssh_client/runscript 10 | 11 | ``` 12 | 13 | sample code: 14 | main.go 15 | ``` 16 | package main 17 | 18 | import ( 19 | "fmt" 20 | "github.com/twr14152/Go_Network_Scripts/ssh_client/runscript" 21 | ) 22 | 23 | func main() { 24 | fmt.Println("Connecting to Group1 hosts") 25 | runscript.Connect("user1", "password1", "group1.txt") 26 | fmt.Println("Connecting to Group2 hosts") 27 | runscript.Connect("user2", "password2", "group2.txt") 28 | } 29 | 30 | ``` 31 | 32 | You can call the hostfile what ever you want. It is neccesary to include the connecting port in the file. 33 | 34 | hostfile.txt 35 | - hostname:port 36 | - ip_address:port 37 | 38 | # This is key 39 | 40 | runscript.go calls unique cmd files for each device using the following naming standard to determine the commands to apply to each device. 41 | 42 | Commands files: 43 | 44 | File name format: 45 | - "file_"+"hostname"+":ssh_Port"+".cfg" 46 | - or - 47 | - "file_"+"ip address"+":ssh_Port"+".cfg" 48 | 49 | Eg. 50 | - file_core_r1:22.cfg 51 | - file_10.0.1.100:8181.cfg 52 | 53 | By using the "file_" in front of the name your able to use IP address as well has hostnames. 54 | 55 | # In summary to use this package you will need to do the following: 56 | ``` 57 | - Import runscript into main.go 58 | - Then use runscript.Connect("username", "password", "hostsfile.txt") to your devices 59 | - Create commands files for each device USING THE FORMAT PROVIDED. 60 | - Create hostfile grouping those hosts that share common login parameters 61 | 62 | ``` 63 | 64 | Example provided: 65 | -------------------- 66 | 67 | # directory files 68 | 69 | ``` 70 |  ls -l 71 | total 20 72 | -rw-r--r-- 1 runner runner 194 Dec 20 15:52 file_131.226.217.143:22.cfg 73 | -rw-r--r-- 1 runner runner 185 Dec 20 16:51 file_64.103.37.14:8181.cfg 74 | -rw-r--r-- 1 runner runner 18 Dec 20 15:53 group1.txt 75 | -rw-r--r-- 1 runner runner 18 Dec 20 16:44 group2.txt 76 | -rw-r--r-- 1 runner runner 318 Dec 20 16:55 main.go 77 |  78 | ``` 79 | 80 | # host_files 81 | ``` 82 |  cat group1.txt 83 | 131.226.217.143:22 84 | 85 |  cat group2.txt 86 | 64.103.37.14:8181 87 |  88 | ``` 89 | # cmds for host1 90 | ``` 91 |  cat file_131.226.217.143\:22.cfg 92 | sh ip int brief 93 | config t 94 | interface loopback74 95 | description script_test_iosxe_dev 96 | ip address 74.74.74.74 255.255.255.255 97 | exit 98 | exit 99 | show ip int brief 100 | config t 101 | no interface loopback 74 102 | exit 103 | exit 104 |  105 | ``` 106 | 107 | # cmds for host2 108 | ``` 109 | cat file_64.103.37.14\:8181.cfg 110 | show ip int brief 111 | config t 112 | interface loopback 75 113 | description script_test_nxos_dev 114 | ip address 75.75.75.75/32 115 | exit 116 | exit 117 | show ip int brief 118 | config t 119 | no interface loopback 75 120 | exit 121 | exit 122 | ``` 123 | 124 | ------------------- 125 | # Results of the program 126 | 127 | ``` 128 |  go run main.go 129 | Connecting to Group1 hosts 130 | [131.226.217.143:22] 131 | 132 | 133 | This is the config file named:file_131.226.217.143:22.cfg 134 | 135 | 136 | 137 | 138 | 139 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 140 | 141 | The following programmability features are already enabled: 142 | - NETCONF 143 | - RESTCONF 144 | 145 | Thanks for stopping by. 146 | 147 | 148 | csr1000v-1#sh ip int brief 149 | Interface IP-Address OK? Method Status Protocol 150 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 151 | GigabitEthernet2 unassigned YES NVRAM administratively down down 152 | GigabitEthernet3 unassigned YES NVRAM administratively down down 153 | Loopback105 192.168.1.1 YES manual up up 154 | Loopback106 192.168.1.2 YES manual up up 155 | csr1000v-1#config t 156 | Enter configuration commands, one per line. End with CNTL/Z. 157 | csr1000v-1(config)#interface loopback74 158 | csr1000v-1(config-if)# description script_test_iosxe_dev 159 | csr1000v-1(config-if)# ip address 74.74.74.74 255.255.255.255 160 | csr1000v-1(config-if)# exit 161 | csr1000v-1(config)#exit 162 | csr1000v-1#show ip int brief 163 | Interface IP-Address OK? Method Status Protocol 164 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 165 | GigabitEthernet2 unassigned YES NVRAM administratively down down 166 | GigabitEthernet3 unassigned YES NVRAM administratively down down 167 | Loopback74 74.74.74.74 YES manual up up 168 | Loopback105 192.168.1.1 YES manual up up 169 | Loopback106 192.168.1.2 YES manual up up 170 | csr1000v-1#config t 171 | Enter configuration commands, one per line. End with CNTL/Z. 172 | csr1000v-1(config)#no interface loopback 74 173 | csr1000v-1(config)#exit 174 | csr1000v-1#exit 175 | Connecting to Group2 hosts 176 | [64.103.37.14:8181] 177 | 178 | 179 | This is the config file named:file_64.103.37.14:8181.cfg 180 | 181 | 182 | 183 | 184 | 185 | stty: standard input: Inappropriate ioctl for device 186 | 187 | IP Interface Status for VRF "default"(1) 188 | Interface IP Address Interface Status 189 | Vlan100 172.16.100.1 protocol-down/link-down/admin-down 190 | Vlan101 172.16.101.1 protocol-down/link-down/admin-down 191 | Vlan102 172.16.102.1 protocol-down/link-down/admin-down 192 | Vlan103 172.16.103.1 protocol-down/link-down/admin-down 193 | Vlan104 172.16.104.1 protocol-down/link-down/admin-down 194 | Vlan105 172.16.105.1 protocol-down/link-down/admin-down 195 | Lo1 172.16.0.1 protocol-up/link-up/admin-up 196 | Lo98 10.98.98.1 protocol-up/link-up/admin-up 197 | Lo99 10.99.99.1 protocol-up/link-up/admin-up 198 | Eth1/5 172.16.1.1 protocol-down/link-down/admin-down 199 | 200 | IP Interface Status for VRF "default"(1) 201 | Interface IP Address Interface Status 202 | Vlan100 172.16.100.1 protocol-down/link-down/admin-down 203 | Vlan101 172.16.101.1 protocol-down/link-down/admin-down 204 | Vlan102 172.16.102.1 protocol-down/link-down/admin-down 205 | Vlan103 172.16.103.1 protocol-down/link-down/admin-down 206 | Vlan104 172.16.104.1 protocol-down/link-down/admin-down 207 | Vlan105 172.16.105.1 protocol-down/link-down/admin-down 208 | Lo1 172.16.0.1 protocol-up/link-up/admin-up 209 | Lo75 75.75.75.75 protocol-up/link-up/admin-up 210 | Lo98 10.98.98.1 protocol-up/link-up/admin-up 211 | Lo99 10.99.99.1 protocol-up/link-up/admin-up 212 | Eth1/5 172.16.1.1 protocol-down/link-down/admin-down 213 |  214 | ``` 215 | -------------------------------------------------------------------------------- /ssh_client/runscript/go.mod: -------------------------------------------------------------------------------- 1 | module runscript 2 | 3 | go 1.15 4 | 5 | require golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 6 | -------------------------------------------------------------------------------- /ssh_client/runscript/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 2 | golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 h1:3wPMTskHO3+O6jqTEXyFcsnuxMQOqYSaHsDxcbUXpqA= 3 | golang.org/x/crypto v0.0.0-20201217014255-9d1352758620/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= 4 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 5 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 6 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 7 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 8 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 9 | -------------------------------------------------------------------------------- /ssh_client/runscript/runscript.go: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2020 Todd Riemenschneider 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package runscript 26 | 27 | import ( 28 | "bufio" 29 | "fmt" 30 | "golang.org/x/crypto/ssh" 31 | "log" 32 | "os" 33 | "time" 34 | ) 35 | 36 | var hostList []string 37 | var user string 38 | var pass string 39 | var hostfile string 40 | 41 | func loginHosts(hostfile string) { 42 | hf, _ := os.Open(hostfile) 43 | scanner := bufio.NewScanner(hf) 44 | scanner.Split(bufio.ScanLines) 45 | for scanner.Scan() { 46 | hostList = append(hostList, scanner.Text()) 47 | } 48 | fmt.Println(hostList) 49 | } 50 | 51 | func Connect(user, pass, hostfile string) { 52 | loginHosts(hostfile) 53 | for _, host := range hostList { 54 | 55 | config := &ssh.ClientConfig{ 56 | User: user, 57 | Auth: []ssh.AuthMethod{ 58 | ssh.Password(pass), 59 | }, 60 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 61 | } 62 | 63 | conn, err := ssh.Dial("tcp", host, config) 64 | time.Sleep(1) 65 | if err != nil { 66 | log.Fatal("Failed to dial: ", err) 67 | } 68 | sess, err := conn.NewSession() 69 | if err != nil { 70 | log.Fatal("Failed to create session: ", err) 71 | } 72 | stdin, err := sess.StdinPipe() 73 | sess.Stdout = os.Stdout 74 | sess.Stderr = os.Stderr 75 | sess.Shell() 76 | // cmds file should use host.cfg name standard 77 | fmt.Println("\n\nThis is the config file named:" + "file_" + host + ".cfg") 78 | fmt.Printf("\n\n\n\n") 79 | cmds, _ := os.Open("file_" + host + ".cfg") 80 | scanner := bufio.NewScanner(cmds) 81 | scanner.Split(bufio.ScanLines) 82 | var lines []string 83 | for scanner.Scan() { 84 | lines = append(lines, scanner.Text()) 85 | } 86 | cmds.Close() 87 | for _, line := range lines { 88 | fmt.Fprintf(stdin, "%s\n", line) 89 | } 90 | fmt.Fprintf(stdin, "exit\n") 91 | fmt.Fprintf(stdin, "exit\n") 92 | sess.Wait() 93 | sess.Close() 94 | } 95 | hostList = nil 96 | } 97 | -------------------------------------------------------------------------------- /ssh_client/ssh_cli_client/README.md: -------------------------------------------------------------------------------- 1 | # ssh_cli_client 2 | 3 | The idea behind this code is that you could quickly gather info on the fly as well as make minor changes if so desired. When the code is run, it will ask you how many devices you want to connect to, as well as what commands you want to run. 4 | You will need to add login credential to main.go. 5 | 6 | 7 | If you have multiple logins you simply run a new instance of RunCli() for each group of devices. 8 | 9 | ### Update main.go with the groups of devices you want to run the script against. 10 | 11 | ``` 12 | func main() { 13 | fmt.Println("This is the login to Group1 hosts") 14 | RunCli("username1", "password1") 15 | //fmt.Println("This is the login to Group2 hosts") 16 | //This will connect to another group of hosts using different auth 17 | //RunCli("username2", "password2") 18 | ``` 19 | ### Running code with show commands: 20 | - For host you need to include ssh port you connecting to. In the host:port format. 21 | ``` 22 | pi@raspberrypi:~/Code_folder/go_folder/go2run/ssh_cli_client $ go run main.go 23 | Connecting to IOS-XE hosts: 24 | Number of hosts: 1 25 | Hostname: fastxe:22 26 | 27 | cmds: show ip int brief | inc up 28 | 29 | 30 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 31 | 32 | The following programmability features are already enabled: 33 | - NETCONF 34 | - RESTCONF 35 | 36 | Thanks for stopping by. 37 | 38 | 39 | csr1000v-1#term len 0 40 | csr1000v-1#show ip int brief | inc up 41 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 42 | Loopback201 10.99.98.1 YES manual up up 43 | csr1000v-1# 44 | csr1000v-1#exit 45 | Connecting to NX-OS hosts: 46 | Number of hosts: 1 47 | Hostname: nxos:8181 48 | 49 | cmds: show ip int brief | inc up 50 | 51 | 52 | stty: standard input: Inappropriate ioctl for device 53 | gl_set_term_size: NULL arguments(s). 54 | Lo1 172.16.0.1 protocol-up/link-up/admin-up 55 | Lo98 10.98.98.1 protocol-up/link-up/admin-up 56 | Lo99 10.99.99.1 protocol-up/link-up/admin-up 57 | pi@raspberrypi:~/Code_folder/go_folder/go2run/ssh_cli_client $ 58 | 59 | ``` 60 | 61 | 62 | 63 | ### Running code with configuration commands + validation commands. 64 | 65 | ``` 66 | pi@raspberrypi:~/Code_folder/go_folder/go2run/ssh_cli_client $ go run main.go 67 | Connecting to IOS-XE hosts: 68 | Number of hosts: 1 69 | Hostname: fastxe:22 70 | 71 | cmds: config t, interface loopback 75, description testing_go_script, ip address 75.75.75.75 255.255.255.255, exit, exit, sh interface description, show ip int brief | inc up 72 | 73 | 74 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 75 | 76 | The following programmability features are already enabled: 77 | - NETCONF 78 | - RESTCONF 79 | 80 | Thanks for stopping by. 81 | 82 | 83 | 84 | csr1000v-1#term len 0 85 | csr1000v-1#config t 86 | Enter configuration commands, one per line. End with CNTL/Z. 87 | csr1000v-1(config)# interface loopback 75 88 | csr1000v-1(config-if)# description testing_go_script 89 | csr1000v-1(config-if)# ip address 75.75.75.75 255.255.255.255 90 | csr1000v-1(config-if)# exit 91 | csr1000v-1(config)# exit 92 | csr1000v-1# sh interface description 93 | Interface Status Protocol Description 94 | Gi1 up up MANAGEMENT INTERFACE - DON'T TOUCH ME 95 | Gi2 admin down down achelove interface 96 | Gi3 admin down down Network Interface 97 | Lo75 up up testing_go_script 98 | Lo201 up up 99 | csr1000v-1# show ip int brief | inc up 100 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 101 | Loopback75 75.75.75.75 YES manual up up 102 | Loopback201 10.99.98.1 YES manual up up 103 | csr1000v-1# 104 | csr1000v-1#exit 105 | Connecting to NX-OS hosts: 106 | Number of hosts: 1 107 | Hostname: nxos:8181 108 | 109 | cmds: config t, interface loopback 76, ip address 76.76.76.76/32, description testing_go_script, exit, exit, show ip int brief | inc up, show interface description 110 | 111 | 112 | stty: standard input: Inappropriate ioctl for device 113 | gl_set_term_size: NULL arguments(s). 114 | Lo1 172.16.0.1 protocol-up/link-up/admin-up 115 | Lo76 76.76.76.76 protocol-up/link-up/admin-up 116 | Lo98 10.98.98.1 protocol-up/link-up/admin-up 117 | Lo99 10.99.99.1 protocol-up/link-up/admin-up 118 | 119 | 120 | ------------------------------------------------------------------------------- 121 | Interface Description 122 | ------------------------------------------------------------------------------- 123 | Lo1 -- 124 | Lo30 My Learning Lab Loopback 125 | Lo76 testing_go_script 126 | Lo98 Configured using OpenConfig Model 127 | Lo99 Full intf config via NETCONF 128 | 129 | ------------------------------------------------------------------------------- 130 | pi@raspberrypi:~/Code_folder/go_folder/go2run/ssh_cli_client $ 131 | 132 | 133 | ``` 134 | 135 | -------------------------------------------------------------------------------- /ssh_client/ssh_cli_client/go.mod: -------------------------------------------------------------------------------- 1 | module ssh_cli_client 2 | 3 | go 1.15 4 | 5 | require golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 6 | -------------------------------------------------------------------------------- /ssh_client/ssh_cli_client/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 2 | golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 h1:sYNJzB4J8toYPQTM6pAkcmBRgw9SnQKP9oXCHfgy604= 3 | golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= 4 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 5 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 6 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 7 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 8 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 9 | -------------------------------------------------------------------------------- /ssh_client/ssh_cli_client/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2020 Todd Riemenschneider 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package main 26 | 27 | import ( 28 | "bufio" 29 | "fmt" 30 | "golang.org/x/crypto/ssh" 31 | "log" 32 | "os" 33 | "strings" 34 | ) 35 | 36 | func commands() map[string][]string { 37 | var count int 38 | var host string 39 | fmt.Print("Number of hosts: ") 40 | fmt.Scanf("%d", &count) 41 | hostCmds := make(map[string][]string) 42 | for i := 1; i <= count; i++ { 43 | fmt.Print("Hostname: ") 44 | fmt.Scanf("%s", &host) 45 | fmt.Println() 46 | reader := bufio.NewReader(os.Stdin) 47 | fmt.Print("cmds: ") 48 | cmds, _ := reader.ReadString('\n') 49 | s := strings.Split(cmds, ",") 50 | fmt.Println() 51 | hostCmds[host] = s 52 | } 53 | return hostCmds 54 | } 55 | 56 | func RunCli(user, pass string) { 57 | 58 | hostData := commands() 59 | 60 | for host, commands := range hostData { 61 | config := &ssh.ClientConfig{ 62 | User: user, 63 | Auth: []ssh.AuthMethod{ 64 | ssh.Password(pass), 65 | }, 66 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 67 | } 68 | conn, err := ssh.Dial("tcp", host, config) 69 | if err != nil { 70 | log.Fatal("Failed to dial: ", err) 71 | } 72 | sess, err := conn.NewSession() 73 | if err != nil { 74 | log.Fatal("Failed to create session: ", err) 75 | } 76 | stdin, _ := sess.StdinPipe() 77 | sess.Stdout = os.Stdout 78 | sess.Stderr = os.Stderr 79 | sess.Shell() 80 | fmt.Fprintf(stdin, "term len 0\n") 81 | for _, v := range commands { 82 | fmt.Fprintf(stdin, "%s\n", v) 83 | } 84 | fmt.Fprintf(stdin, "exit\n") 85 | fmt.Fprintf(stdin, "exit\n") 86 | sess.Wait() 87 | sess.Close() 88 | } 89 | } 90 | 91 | func main() { 92 | fmt.Println("Connecting to Group1 hosts:") 93 | RunCli("developer", "C1sco12345") 94 | //fmt.Println("Connecting to Group2 hosts:") 95 | //RunCli("username2", "password2") 96 | //fmt.Println("Connecting to Group3 hosts:") 97 | //RunCli("username3", "password3") 98 | 99 | } 100 | -------------------------------------------------------------------------------- /ssh_client/ssh_client/README.md: -------------------------------------------------------------------------------- 1 | # ssh_client 2 | The goal of this SSH script is to use host and cmd files to change and validate device configuration. 3 | 4 | In the code you will add your login credentials and hostfile as parameters of the connect function in main.go. 5 | 6 | You can call the hostfile what ever you want. It is neccesary to include the connecting port in the file. 7 | 8 | hostfile.txt 9 | - hostname:port 10 | - ip_address:port 11 | 12 | Main.go calls unique cmd files for each device using the following naming standard to determine the commands to apply to each device. 13 | 14 | 15 | Commands files: 16 | 17 | File name format: 18 | - "file_"+"hostname"+":ssh_Port"+".cfg" 19 | - or - 20 | - "file_"+"ip address"+":ssh_Port"+".cfg" 21 | 22 | Eg. 23 | - file_core_r1:22.cfg 24 | - file_10.0.1.100:8181.cfg 25 | 26 | By using the "file_" in front of the name your able to use IP address as well has hostnames. 27 | 28 | In sum to use this package you will need to do the following: 29 | ``` 30 | - Create commands files for each device using naming format provided. 31 | - Create hostfile and add it and your login parameters to the body of func main() in main.go 32 | - If you have multiple logins you can create groups to put the devices in and use those for host files. 33 | 34 | ``` 35 | 36 | Example provided: 37 | -------------------- 38 | 39 | #Package files 40 | 41 | ``` 42 | $ ls -l 43 | total 36 44 | -rw-r--r-- 1 pi pi 185 Dec 15 18:15 file_fastxe:22.cfg 45 | -rw-r--r-- 1 pi pi 176 Dec 15 18:15 file_nxos:8181.cfg 46 | -rw-r--r-- 1 pi pi 103 Dec 15 18:24 go.mod 47 | -rw-r--r-- 1 pi pi 1045 Dec 15 18:24 go.sum 48 | -rw-r--r-- 1 pi pi 10 Dec 15 18:17 group1.txt 49 | -rw-r--r-- 1 pi pi 10 Dec 15 18:25 group2.txt 50 | -rw-r--r-- 1 pi pi 1891 Dec 15 18:27 main.go 51 | -rw-r--r-- 1 pi pi 7211 Dec 15 18:39 README.md 52 | $ 53 | 54 | 55 | # host_files 56 | ``` 57 | $ cat group1.txt 58 | ``` 59 | fastxe:22 60 | ``` 61 | ``` 62 | ``` 63 | $ cat group2.txt 64 | ``` 65 | nxos:8181 66 | ``` 67 | ``` 68 | ``` 69 | # cmds for host1 70 | ``` 71 | ``` 72 | ``` 73 | $ cat file_fastxe\:22.cfg 74 | sh ip int brief 75 | config t 76 | interface loopback74 77 | description Script_test 78 | ip address 74.74.74.74 255.255.255.255 79 | exit 80 | exit 81 | show ip int brief 82 | config t 83 | no interface loopback 74 84 | exit 85 | exit 86 | ``` 87 | ``` 88 | ``` 89 | 90 | # cmds for host2 91 | ``` 92 | ``` 93 | ``` 94 | $ cat file_nxos\:8181.cfg 95 | show ip int brief 96 | config t 97 | interface loopback 75 98 | description Script_test 99 | ip address 75.75.75.75/32 100 | exit 101 | exit 102 | show ip int brief 103 | config t 104 | no interface loopback 75 105 | exit 106 | exit 107 | $ 108 | ```` 109 | ------------------- 110 | # Results of the program 111 | 112 | ``` 113 | $ go run main.go 114 | Connecting to Group1 hosts: 115 | [fastxe:22] 116 | 117 | 118 | This is the config file named:file_fastxe:22.cfg 119 | 120 | 121 | 122 | 123 | 124 | Welcome to the DevNet Sandbox for CSR1000v and IOS XE 125 | 126 | The following programmability features are already enabled: 127 | - NETCONF 128 | - RESTCONF 129 | 130 | Thanks for stopping by. 131 | 132 | 133 | 134 | csr1000v-1#sh ip int brief 135 | Interface IP-Address OK? Method Status Protocol 136 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 137 | GigabitEthernet2 unassigned YES NVRAM administratively down down 138 | GigabitEthernet3 unassigned YES NVRAM administratively down down 139 | Loopback1 10.10.1.1 YES other up up 140 | Loopback2 10.20.1.1 YES other up up 141 | Loopback10 100.100.100.10 YES manual up up 142 | Loopback20 22.22.22.22 YES manual up up 143 | Loopback30 33.33.33.33 YES manual up up 144 | Loopback100 172.16.1.101 YES manual up up 145 | Loopback101 unassigned YES unset up up 146 | Loopback140 10.12.12.14 YES manual up up 147 | Loopback141 10.12.12.15 YES manual up up 148 | Loopback200 172.31.1.200 YES manual up up 149 | csr1000v-1#config t 150 | Enter configuration commands, one per line. End with CNTL/Z. 151 | csr1000v-1(config)#interface loopback74 152 | csr1000v-1(config-if)# description Script_test 153 | csr1000v-1(config-if)# ip address 74.74.74.74 255.255.255.255 154 | csr1000v-1(config-if)# exit 155 | csr1000v-1(config)#exit 156 | csr1000v-1#show ip int brief 157 | Interface IP-Address OK? Method Status Protocol 158 | GigabitEthernet1 10.10.20.48 YES NVRAM up up 159 | GigabitEthernet2 unassigned YES NVRAM administratively down down 160 | GigabitEthernet3 unassigned YES NVRAM administratively down down 161 | Loopback1 10.10.1.1 YES other up up 162 | Loopback2 10.20.1.1 YES other up up 163 | Loopback10 100.100.100.10 YES manual up up 164 | Loopback20 22.22.22.22 YES manual up up 165 | Loopback30 33.33.33.33 YES manual up up 166 | Loopback74 74.74.74.74 YES manual up up 167 | Loopback100 172.16.1.101 YES manual up up 168 | Loopback101 unassigned YES unset up up 169 | Loopback140 10.12.12.14 YES manual up up 170 | Loopback141 10.12.12.15 YES manual up up 171 | Loopback200 172.31.1.200 YES manual up up 172 | csr1000v-1#config t 173 | Enter configuration commands, one per line. End with CNTL/Z. 174 | csr1000v-1(config)#no interface loopback 74 175 | csr1000v-1(config)#exit 176 | csr1000v-1#exit 177 | Connecting to Group2 hosts: 178 | [nxos:8181] 179 | 180 | 181 | This is the config file named:file_nxos:8181.cfg 182 | 183 | 184 | 185 | 186 | 187 | stty: standard input: Inappropriate ioctl for device 188 | 189 | IP Interface Status for VRF "default"(1) 190 | Interface IP Address Interface Status 191 | Vlan100 172.16.100.1 protocol-down/link-down/admin-down 192 | Vlan101 172.16.101.1 protocol-down/link-down/admin-down 193 | Vlan102 172.16.102.1 protocol-down/link-down/admin-down 194 | Vlan103 172.16.103.1 protocol-down/link-down/admin-down 195 | Vlan104 172.16.104.1 protocol-down/link-down/admin-down 196 | Vlan105 172.16.105.1 protocol-down/link-down/admin-down 197 | Lo1 172.16.0.1 protocol-up/link-up/admin-up 198 | Lo98 10.98.98.1 protocol-up/link-up/admin-up 199 | Lo99 10.99.99.1 protocol-up/link-up/admin-up 200 | Eth1/5 172.16.1.1 protocol-down/link-down/admin-down 201 | 202 | IP Interface Status for VRF "default"(1) 203 | Interface IP Address Interface Status 204 | Vlan100 172.16.100.1 protocol-down/link-down/admin-down 205 | Vlan101 172.16.101.1 protocol-down/link-down/admin-down 206 | Vlan102 172.16.102.1 protocol-down/link-down/admin-down 207 | Vlan103 172.16.103.1 protocol-down/link-down/admin-down 208 | Vlan104 172.16.104.1 protocol-down/link-down/admin-down 209 | Vlan105 172.16.105.1 protocol-down/link-down/admin-down 210 | Lo1 172.16.0.1 protocol-up/link-up/admin-up 211 | Lo75 75.75.75.75 protocol-up/link-up/admin-up 212 | Lo98 10.98.98.1 protocol-up/link-up/admin-up 213 | Lo99 10.99.99.1 protocol-up/link-up/admin-up 214 | Eth1/5 172.16.1.1 protocol-down/link-down/admin-down 215 | $ 216 | ``` 217 | -------------------------------------------------------------------------------- /ssh_client/ssh_client/file_fastxe:22.cfg: -------------------------------------------------------------------------------- 1 | sh ip int brief 2 | config t 3 | interface loopback74 4 | description Script_test 5 | ip address 74.74.74.74 255.255.255.255 6 | exit 7 | exit 8 | show ip int brief 9 | config t 10 | no interface loopback 74 11 | exit 12 | exit 13 | 14 | -------------------------------------------------------------------------------- /ssh_client/ssh_client/file_nxos:8181.cfg: -------------------------------------------------------------------------------- 1 | show ip int brief 2 | config t 3 | interface loopback 75 4 | description Script_test 5 | ip address 75.75.75.75/32 6 | exit 7 | exit 8 | show ip int brief 9 | config t 10 | no interface loopback 75 11 | exit 12 | exit 13 | 14 | -------------------------------------------------------------------------------- /ssh_client/ssh_client/go.mod: -------------------------------------------------------------------------------- 1 | module ssh_client 2 | 3 | go 1.15 4 | 5 | require golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 // indirect 6 | -------------------------------------------------------------------------------- /ssh_client/ssh_client/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 2 | golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c h1:9HhBz5L/UjnK9XLtiZhYAdue5BVKep3PMmS2LuPDt8k= 3 | golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= 4 | golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 h1:sYNJzB4J8toYPQTM6pAkcmBRgw9SnQKP9oXCHfgy604= 5 | golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= 6 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 7 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 8 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 9 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 10 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 11 | -------------------------------------------------------------------------------- /ssh_client/ssh_client/group1.txt: -------------------------------------------------------------------------------- 1 | fastxe:22 2 | -------------------------------------------------------------------------------- /ssh_client/ssh_client/group2.txt: -------------------------------------------------------------------------------- 1 | nxos:8181 2 | -------------------------------------------------------------------------------- /ssh_client/ssh_client/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2020 Todd Riemenschneider 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | package main 26 | 27 | import ( 28 | "bufio" 29 | "fmt" 30 | "golang.org/x/crypto/ssh" 31 | "log" 32 | "os" 33 | "time" 34 | ) 35 | 36 | var hostList []string 37 | var user string 38 | var pass string 39 | var hostfile string 40 | 41 | func loginHosts(hostfile string) { 42 | hf, _ := os.Open(hostfile) 43 | scanner := bufio.NewScanner(hf) 44 | scanner.Split(bufio.ScanLines) 45 | for scanner.Scan() { 46 | hostList = append(hostList, scanner.Text()) 47 | } 48 | fmt.Println(hostList) 49 | } 50 | 51 | func connect(user, pass, hostfile string) { 52 | loginHosts(hostfile) 53 | for _, host := range hostList { 54 | 55 | config := &ssh.ClientConfig{ 56 | User: user, 57 | Auth: []ssh.AuthMethod{ 58 | ssh.Password(pass), 59 | }, 60 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), 61 | } 62 | 63 | conn, err := ssh.Dial("tcp", host, config) 64 | time.Sleep(1) 65 | if err != nil { 66 | log.Fatal("Failed to dial: ", err) 67 | } 68 | sess, err := conn.NewSession() 69 | if err != nil { 70 | log.Fatal("Failed to create session: ", err) 71 | } 72 | stdin, err := sess.StdinPipe() 73 | sess.Stdout = os.Stdout 74 | sess.Stderr = os.Stderr 75 | sess.Shell() 76 | // cmds file should use host.cfg name standard 77 | fmt.Println("\n\nThis is the config file named:" + "file_" + host + ".cfg") 78 | fmt.Printf("\n\n\n\n") 79 | cmds, _ := os.Open("file_" + host + ".cfg") 80 | scanner := bufio.NewScanner(cmds) 81 | scanner.Split(bufio.ScanLines) 82 | var lines []string 83 | for scanner.Scan() { 84 | lines = append(lines, scanner.Text()) 85 | } 86 | cmds.Close() 87 | for _, line := range lines { 88 | fmt.Fprintf(stdin, "%s\n", line) 89 | } 90 | fmt.Fprintf(stdin, "exit\n") 91 | fmt.Fprintf(stdin, "exit\n") 92 | sess.Wait() 93 | sess.Close() 94 | } 95 | hostList = nil 96 | } 97 | func main() { 98 | fmt.Println("Connecting to Group1 hosts:") 99 | connect("user1", "password1", "group1.txt") 100 | fmt.Println("Connecting to Group2 hosts:") 101 | connect("user2", "password2", "group2.txt") 102 | } 103 | -------------------------------------------------------------------------------- /using_go_mod_example.txt: -------------------------------------------------------------------------------- 1 | This is a simple example of using go mod to keep dependencies updated. 2 | There's probably a lot more you can do with it but lets keep it simple. 3 | 4 | Create directory using filename leaving off the ".go" suffix. 5 | 6 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder $ mkdir ssh_using_cli_args 7 | 8 | If you have a script already created move it into the folder otherwise create it within. 9 | 10 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder $ mv ssh_using_cli_args.go ssh_using_cli_args 11 | 12 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder/ssh_using_cli_args $ go mod init ssh_using_cli_args 13 | go: creating new go.mod: module ssh_using_cli_args 14 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder/ssh_using_cli_args $ ls -l 15 | total 8 16 | -rw-r--r-- 1 pi pi 35 Nov 21 08:56 go.mod 17 | -rw-r--r-- 1 pi pi 1109 Nov 21 08:37 ssh_using_cli_args.go 18 | 19 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder/ssh_using_cli_args $ go build 20 | go: finding module for package golang.org/x/crypto/ssh 21 | go: downloading golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 22 | go: found golang.org/x/crypto/ssh in golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 23 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder/ssh_using_cli_args $ ls -l 24 | total 3824 25 | -rw-r--r-- 1 pi pi 99 Nov 21 08:57 go.mod 26 | -rw-r--r-- 1 pi pi 832 Nov 21 08:57 go.sum 27 | -rwxr-xr-x 1 pi pi 3903398 Nov 21 08:57 ssh_using_cli_args 28 | -rw-r--r-- 1 pi pi 1109 Nov 21 08:37 ssh_using_cli_args.go 29 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder/ssh_using_cli_args $ cat go.mod 30 | module ssh_using_cli_args 31 | 32 | go 1.15 33 | 34 | require golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 35 | 36 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder/ssh_using_cli_args $ cat go.sum 37 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 38 | golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 h1:phUcVbl53swtrUN8kQEXFhUxPlIlWyBfKmidCu7P95o= 39 | golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= 40 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 41 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 42 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 43 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 44 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 45 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder/ssh_using_cli_args $ 46 | 47 | To run the file 48 | 49 | pi@RaspPi4:~/Coding/Go_folder/netOps/ssh_folder/ssh_using_cli_args $ ./ssh_using_cli_args show ip int brief 50 | 51 | --------------------------------------------------------------------------------