Scripting & API

 

Python is an interpreted programming language

Node.js is a JavaScript runtime. Developers like it because the JavaScript foundation provides a consistent language across web (sometimes called "frontend") and application (sometimes called "backend") development.

Atom is an open source text editor 

Postman is a powerful REST API client that provides a set of capabilities for testing, exploring, and writing REST APIs.

ngrok is an application that you run on your environment, and it builds a connection path from the public internet to your local workstation. Because you start the tool from your workstation, ngrok works well through firewalls, proxies, and NAT services

If you do NOT have AnyConnect, open source alternative OpenConnect

An application container is a packaging method to combine application code and any dependencies in an efficient format so that it can be easily run in isolation from other containers on a host.

Docker is an application container engine

Git is Source Control Systems: git-bash

Python Virtual Environments are a method of creating isolated "environments" with specific versions of Python installed along with independent sets of libraries and dependencies.

  py -3 -m venv py3-venv
  source py3-venv/Scripts/activate
  deactivate

vscode : Visual Studio Code   code.visualstudio.com








Download and installation

python.org


pip is the package installer for Python
pypi.org


Data Types
   Strings, Integers, Lists and Dictionaries


Installing and importing packages

The Python Package Index (PyPI) is a repository of software for the Python programming language.

pypi.org
   search for junos-eznc

command "pip" is used to install package.


in Windows cmd, not Python 

  pip install junos-eznc

pip freeze    (show package version)


Find pip installed packages

pip list


ssh into network devices using netmiko 


pip install netmiko

from netmiko import ConnectHandler
cat2960 = {
    "device_type": "cisco_ios",
    "ip": "192.168.2.20",
    "username": "admin",
    "password": "admin",
    "secret": "cisco"
}
net_connect = ConnectHandler(**cat2960)
net_connect.enable()
output= net_connect.send_command("show vlan brief")
print(output)
for vlan in range (10,51,10):
    config_commnds = ["vlan " + str(vlan), "name Netmiko_VLAN_" + str(vlan) ]
    output = net_connect.send_config_set(config_commnds)
    print (output)
output= net_connect.send_command("show vlan brief")
print(output)
net_connect.disconnect()

print(net_connect.find_prompt())


from netmiko import ConnectHandler
from getpass import getpass
cat2960 = {
    "device_type": "cisco_ios",
    "ip": "192.168.2.20",
    "username": "admin",
    "password": getpass(),
    "secret": "cisco"
}
net_connect = ConnectHandler(**cat2960)
print(net_connect.find_prompt())
net_connect.disconnect()



What’s the Difference Between YAML and JSON?

https://aws.amazon.com/compare/the-difference-between-yaml-and-json/#:~:text=Both%20represent%20data%20as%20key,language%20to%20support%20developer%20use.



Python Collections (Arrays)

There are four collection data types in the Python programming language:

  • List is a collection which is ordered and changeable. Allows duplicate members.
  • Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
  • Set is a collection which is unordered, unchangeable*, and unindexed. No duplicate members.
  • Dictionary is a collection which is ordered** and changeable. No duplicate members.
*Set items are unchangeable, but you can remove and/or add items whenever you like.

**As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier, dictionaries are unordered.



GIT  

gitbash

first use:

git config --global user.name "ffff llll"
git config --global user.email "ffffllll@gmail.com"
git config --global init.defaultBranch main

-h    #  help 
git help xxx 


cd c:/Users/xxx/sockets

git init

git status

git add filename

to ignore file or directory
   create file .gitignore  under folder
   edit .gitignore
      #ignore all .txt files
      *.txt

track all files:
  git add .
  git add --all
  git -A

git commit -m "my commit"
git commit -a -m "my commit"  (all changes)

git diff

git mv      (change file name)

git log
git log --oneline
git log -p


git branch yyyy    (create a new branch)
git branch

git switch yyyy

git merge -m "made change in branch" yyyy

git branch -d yyyy





github

create repository on github, there are commands for you to push local repository to cloud

if change is made on cloud:
git fetch
git merch
or
         git pull




Regular Expression


ip_pattern = r'\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b'

email address 
   \w+@\w+\.w+





















Comments

Popular posts from this blog

Firepower FMC and FTD troubleshooting

ASA IKEv1 VPN troubleshooting Steps and Tips

Firepower 2100/1100 FTD/ASA initial setup, reimage, upgrade.