Monday, March 15, 2021

Apple MacBook Air M1 for Network Engineers Part 3

If you have been following along you now have macOS tuned up and some basic applications installed. If you need to read other parts of this series:

In part 3 we will continue installing applications.



Sublime text

One of the most popular editors for python developers. There is a free version that is fully functional but will ask you to buy once in a while and a paid version for $74.95. The license for the paid version lets you install it on all of your personal computers and it runs on Mac, Linux, and Windows so I purchased a license.

There are many tutorials on setting up Sublimetext for developers. 

realpython.com has some of my favorite tutorials:

Setting Up Sublime Text 3 for Full Stack Python Development

realpython.com also sells a package on python/sublimetext that includes detailed videos and pdfs on Sublimetext and Python for $59. I purchased it and was not disappointed. In fact, I signed up for the realpython.com membership for $100 per year.

Why is it so hard to find good and clear instructions on how to make Sublime more Python friendly? 

There are many reasons to give Sublime text a try if you are a network engineer, one of my favorites is that you can put a list of all the open files on the left side. This is much better than notepad ++ on Windows if you are working with several files at one time. You can even click and drag the files to change their order in the "Open Files" window. 




Installation

  • Download the package from www.sublimetext.com
  • Open the dmg file.
  • Drag to the applications folder
  • Set Sublimetext as the default editor for text documents.
  • In finder, locate a .txt file, right-click, get info, set "Open with" to Sublimetext.app.


Set the option to open files in the same window but a new tab.

Go to “Sublime Text” → “Preferences” → “Settings.”

Add the following property to your Sublime user configuration file:


{
	"open_files_in_new_window": false
}


The windows will look like this:



If there are already settings in the file, just add the 

"open_files_in_new_window": false 

between the starting and closing brackets on its own line. All of the lines except the last one have to have a comma at the end.

Save and close the two settings windows that opened. Now when you double click on a file it will open in the same window, in a new tab.

Reference

Sublime text open files same window

Zooming

To increase the text size
Press "⌘" and tap "+"

To decrease the text size
Press "⌘" and tap "-"


Returning to your default text size

Add the following to your keyboard bindings (found under Preferences)...

{ "keys": ["super+0"], "command": "reset_font_size" }

Super is the ⌘ key on macOS (ctrl on Windows/Linux)

super+0 would normally focus the 9th open tab in a Window, so you'll be overriding that behavior.

I found this great tip in the link below.

Reference

 

Using Snippets

This allows you to create snippets of text and insert them with a "trigger word" or from the tools menu. This site shows how to get started. There is an error in how to create a new snippet. Instead of tools, new snippet, it's tools, developer, new snippet.

quickly insert text and code with sublime text snippets

 Here is a sample snippet I made to start a config file for a cisco IOS-XE switch.

 

<snippet>
	<content><![CDATA[
no service pad
service tcp-keepalives-in
service tcp-keepalives-out
service timestamps debug datetime msec localtime
service timestamps log datetime msec localtime
service password-encryption
service linenumber
service sequence-numbers
service counters max age 5
no service dhcp

clock timezone PST -8 0
clock summer-time PDT recurring

no ip source-route
no ip gratuitous-arps

no ip domain lookup

login on-failure log
login on-success log
ipv6 nd raguard policy HOST_POLICY

spanning-tree mode rapid-pvst
spanning-tree portfast default

archive
 log config
  logging enable
  logging size 1000

interface  GigabitEthernet1/0/1
 switchport access vlan xxx
 switchport mode access
 switchport nonegotiate
 load-interval 30
 no cdp enable
 ipv6 nd raguard attach-policy HOST_POLICY
 storm-control broadcast level 1.00
 storm-control multicast level 1.00
 ip verify source
 exit

ip default-gateway x.x.x.x
ip forward-protocol nd
no ip http server
ip http authentication local
ip http secure-server
ip http secure-ciphersuite aes-256-cbc-sha ecdhe-rsa-aes-gcm-sha2 ecdhe-ecdsa-aes-gcm-sha2 
ip http tls-version TLSv1.2 
ip ssh rsa keypair-name SSH-KEYS
ip ssh version 2
ip ssh server algorithm mac hmac-sha2-256 hmac-sha2-512
ip ssh server algorithm encryption aes256-ctr aes192-ctr aes128-ctr
ip scp server enablebanner exec ^CC
*********************************************************
Switch Name:   xxxxxxxx
Description:   yyyyyyyyyyyyyyyy
*********************************************************
^C
$1
]]></content>
	<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>basic-cisco</tabTrigger>
	<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>text</scope>
<description> Cisco start up </description>
</snippet>

I used "basic-cisco" as the trigger so I can type basic-cisco [tab] and sublime text inserts it and moves the cursor to a new line. Obviously, basic-HPE, basic-Arubacx will be next!

 I could also click tools, snippet, and pick it from the list.



The part of the snippet "<description> Cisco start up </description>" sets the description you see on the right of the men.


Open Sublime Text from the terminal

A lot of time I want to just type "subl <filename>" from the terminal to edit a file. I also want to use Sublime text for my git commit messages. Sublime provides instructions to set this up on macOS.

Setup

The first task is to make a symlink to subl. Assuming you've placed Sublime Text in the Applications folder, and that you have a ~/bin directory in your path, you can run:


ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl


The EDITOR environment variable

To use Sublime Text as the editor for many commands that prompt for input, set your EDITOR environment variable:

export EDITOR='subl -w'

Specifying -w will cause the subl command to not exit until the file is closed.

On my M1 I had to add the bin folder and this to the .zshrc file:

export PATH=$HOME/bin:$PATH
 

to make this work but now I can just type subl to start sublime text from the terminal.


Reference


Finding Differences

One really useful feature in Sublime text is the difference engine. An example will make it clear. 

In this file I changed the following:

interface 1/1-1/48
 
to

interface 1/1-1/48,2/1-2/48,3/1-3/48

In Sublime text, I right clicked over the line and selected "Show Diff Hunk"


Now Sublime text shows an orange bar on the left and the old string. Right clicking over the line again will show "Hide Diff Hunk", Revert Diff Hunk and show unsaved changes.

The "Show Unsaved Changes" will open a "Git" style windows and show you all the unsaved changes in the file.

--- /Users/mhubbard/GoogleDrive/01_Vector/network Refresh/Site-49/2930.txt  Fri Sep 17 09:58:10 2021
+++ /Users/mhubbard/GoogleDrive/01_Vector/network Refresh/Site-49/2930.txt  Sun Sep 19 16:21:35 2021
@@ -13,7 +13,7 @@
 time daylight-time-rule continental-us-and-canada
 time timezone -480
 spanning-tree
-interface 1/1-1/48
+interface 1/1-1/48,2/1-2/48,3/1-3/48
    rate-limit bcast in percent 1



The Network Tech Cisco plugin

This is a great open-source plug-in for Cisco network engineers. I have found that it does a reasonable job highlighting Aruba text and the network calculations work.

It highlights the keywords in the code, works with IOS, IOS-XR, Nexus, ASA, and ACE code. It also has:

  • code completion
  • Mask Conversions
  • Quick Info - Display subnet information
  • Format MAC Addresses by Colon, Dash or Dot
  • Password Decode - Decode type 7 passwords
  • Jumping - Quickly jump around large configuration using Symbols
  • Search for networks

Installation

Install Sublime Text's Package Control
Tools - Command Pallet
Install Package Control
<enter>




Install the package:
Tools - Command Pallet

 Package Control: Install Package
 [enter]
 Network Tech
[enter]

Set the syntax type

Open a file to edit or start a new file.

Supported configurations:

  • Cisco ASA
  • Cisco ACE
  • Cisco IOS
  • Cisco IOS XR
  • Cisco NXOS

Set the syntax from the command pallet

Tools - Command Pallet OR cmd+shift+p

Set Syntax: Cisco IOS <enter>


File extensions

If a configuration file has a specific file extension and is opened in Sublime Text, the syntax will be automatically be set:

  • Cisco ASA - *.cisco-asa - *.asa
  • Cisco ACE - *.cisco-ace
  • Cisco IOS - *.cisco-ios - *.ios
  • Cisco IOS XR - *.cisco-ios-xr - *.ios-xr
  • Cisco NXOS - *.cisco-nxos - *.cisco-nexus - *.nxos

Here is a screenshot of a highlighted configuration


Completions

Configuration snippets and autocompletion are suggested based on the syntax and configuration mode.

For example, I started typing errd and it suggested the following:


Mask Conversions

type a / and the conversion window will pop up. Once you find the mask you want press [enter]


In this example, pressing [enter] will insert 255.255.255.0

You can press ctrl+space to toggle between the netmask, wildcard mask and /

Jumping

One of the greatest features, if you are working on a large configuration file, is the ability to jump to commands that enter a configuration mode. For example, to jump to "interface vlan 20" press "cmd+r" and a dialog box will appear:


Type "vlan 20". 

In the search box select "interface Vlan20" and it will jump to that line. In this case, it's on line 685. 

You can search for more than just interfaces. Here I entered ip to find an access-list.


You can also jump to "line con" or "line vty"


Type 7 password decoding

Cisco type 7 passwords aren't hashed, they are "encoded' so they are reversible. Network Tech has a handy feature to decode them.

In a file that has a type 7 password:

  • Press Shift (⇧) + Command (⌘) + p to open the command palette
  • Enter "Network Tech: Decode Passwords"

You will see the passwords from the file, select the one you want to decode



In this example:

username cisco privilege 15 password 7 13061E01080355

It will ask if you want to save the password to the clipboard or display it. Here is what it looks like if you choose to display:


Listing network details

If you highlight an IP address and subnet mask, network tech list all the details for the subnet:




Reference

Network Tech


Compare Side-By-Side plugin


This package adds a simple side-by-side comparison tool to Sublime Text. I like MELD for comparing files but this control is very convenient since it's integrated into Sublime and works well.

Features
  • Easily select two tabs or selections to compare
  • Comparison results open in a new window
  • Empty lines added so common code lines up
  • Count number of lines changed
  • Highlighting of changed lines
  • Intra-line diff highlighting
  • Synchronized scrolling

Installation Options
  • Search for and install using Package Control (⌘+↑+P, “Install Package”)
  • (Preferences -> Browse Packages)

Usage Options
Right-click on a tab and select “Compare with…”
Right-click somewhere in the active view and select “Compare with…”
Right-click on a tab and select “Compare with active tab”
Highlight text, right-click -> “Mark selection for comparison”
Mark a second selection, then right-click -> “Compare selections”
Create two selections by holding CTRL, then “Compare selections”
From the command line: see README_COMMANDS.md
Jump to next: Alt+N, Jump to previous: Alt+P


Reference

Compare Side-By-Side


Using Regular Expressions

Sublime text supports regular expressions or Regex. This is a very powerful feature for searching and replacing text. I'm not going to lie to you, they are confusing but some simple concepts can get you a long way. 

Replacing vlan20 with vlan 20

I have been replacing a lot of Cisco equipment with Aruba. Usually, I don't try to copy Cisco configs over and modify, I would create a new Aruba template with the correct syntax and build a new configuration. 

Today I needed to add several SVIs from a Cisco to an Aruba. A template didn't make sense because it was just one switch, but I needed to update about 30 interface statements. Regex to the rescue! 

Here is what we will enter into the search/replace dialog:

find: interface ([vV]lan)(\d{1,3})
Replace: $1 $2

The () create a "capture group" that allows you to use the text it found in the replace window. The capture groups start at 1 and increment by 1. 

In this example, the first capture group matches on v or V.

The second matches on digits "\d" and the {1,3} matches 1, 2 or 3 digits.

In the replace dialog, click the icon on the far left that looks like a '.*". This puts the search box in regex mode.


Replacing text from the beginning of a line

Given a file with strings like this:

01_BRAD-MDF-AdminTL-STK1-2-config-output.txt:Gi2/0/10                       up             up       < Surv Serv 10.196.250.2 1c98.ec15.a338 > 


I just wanted the text starting with < and ending with >

This regex did the trick

^.*<

The "^" character means start at the beginning of the line
The "." means match one character
The "*" 0 or more of the preceding expression
The "<" was the first character that I wanted to keep.

The replace statement was just "<".

Here is what it looked like in sublime text:


Click the image to enlarge


I had 156 lines like this and with regex it took about 30 seconds to get the text I needed.


Regex quantifiers

Change Gi1/1 to Gi1/0/1 and repeat all other interfaces in the file

Find: (Gi[0-9])/([0-9]+)
Replace: $1/0/$2

Note:
You could also use (Gi[0-9])/([0-9]{1,2}) since the interfaces range from 1-48, 2 digits.

Quantifier  Meaning
A?          Match regular expression A zero or one times
A*          Match regular expression A zero or more times
A+          Match regular expression A one or more times
A{m}        Match regular expression A exactly m times
A{m,n}      Match regular expression A between m and n times (included)

The quantifiers are a powerful feature of regex. Here are some examples using interfaces.

The ? quantifier
Not that it matched just the first digit after the /


The * quantifier
Obviously there isn't a switch with 100,000,000 ports, I made that up to show that the "*" matches 0 or more times.


and here zero instances! Don't forget about 0 times, it can catch you by surprise.



The + quantifier
Here is an example of the "or more times"


Notice that unlike the "*" it doesn't match on 0 times


The {} quantifier
This quantifier allows you to pick exactly how many matches you want. Perfect for an interface.

Here is an example for matching the regex exactly 2 times



Here is an example for matching the regex 1 or 2 times. 




Reference


Speedtest-cli

https://github.com/sivel/speedtest-cli

Installation

Pip install speedtest-cli


speedtest-cli
Retrieving speedtest.net configuration...
Testing from Spectrum (71.84.93.96)...
Retrieving speedtest.net server list...
Selecting best server based on ping...
Hosted by Cox - Orange County (Orange County, CA) [51.76 km]: 27.113 ms
Testing download speed................................................................................
Download: 102.39 Mbit/s
Testing upload speed......................................................................................................
Upload: 21.24 Mbit/s

 

Iterm2

Installation
Download here: Iterm2
  • Open the zip file.
  • select "Automatically update".
  • move app to applications.
  • In Applications, select iTerm, right click, get info, Check "Open in Rosetta".
Iterm2 is a great terminal emulator. It has so many features you will have to read the documentation at:
iterm2 documentation

Onyx

Operating system utilities for macOS
Onyx Download
OnyX is a multifunction utility that you can use to verify the structure of the 
system files, to run miscellaneous maintenance and cleaning tasks, to 
configure parameters in the Finder, Dock, Safari, and some Apple applications, 
to delete caches, to remove certain problematic folders and files, 
to rebuild various databases and indexes, and more.
Download the package, move to the application folder


Ticker

Ticker - Stock ticker for the command line
Ticker Github page

Features

Live stock price quotes
Track value of your stock positions
Support for multiple cost basis lots
Support for pre and post market price quotes

Ok, this isn't network engineering related in anyway but you should be investing in the stock market.
Ticker is a fun little terminal app that lets you monitor stocks.

Installation
brew install achannarasappa/tap/ticker

Ticker uses ~/.ticker.yaml for configuration. Below is the default yaml file. Put stock symbols
in the watchlist area to watch them.


If you own stocks, put them in the Lots area. It's pretty self explanatory. Put the stock symbol
after symbol:, the quantity you own after quantity and the purchase cost after unit_cost.

Then open a terminal and type ticker [enter]
 
# ~/.ticker.yaml
show-summary: true
show-tags: true
show-fundamentals: true
show-separator: true
show-holdings: true
interval: 5
currency: USD
watchlist:
  - NET
  - TEAM
  - ESTC
  - BTC-USD
lots:
  - symbol: "ABNB"
    quantity: 35.0
    unit_cost: 146.00
  - symbol: "ARKW"
    quantity: 20.0
    unit_cost: 152.25
  - symbol: "ARKW"
    quantity: 20.0
    unit_cost: 145.35
















2 comments:

  1. It's a beautiful thing to be appreciated... Keep it up, thanks for sharing.
    After looking through a few blog articles on your website,
    we sincerely appreciate the way you blogged.
    Text Sublime

    ReplyDelete
  2. Hubbard On Networking: Apple Macbook Air M1 For Network Engineers Part 3 >>>>> Download Now

    >>>>> Download Full

    Hubbard On Networking: Apple Macbook Air M1 For Network Engineers Part 3 >>>>> Download LINK

    >>>>> Download Now

    Hubbard On Networking: Apple Macbook Air M1 For Network Engineers Part 3 >>>>> Download Full

    >>>>> Download LINK eR

    ReplyDelete