Networking, Security & Cloud Knowledge

Friday, December 17, 2021

Microsoft Azure

Microsoft Azure cloud Networking components:

Azure terms used for networking component that my be useful for AZ-900 Foundation or administration exam. 

  1. vNet (Virtual Network):
    • It work like logical network boundary, represents supernet allocated for Azure resource group.
    • Under vNet we can create multiple subnet. Minimum one subnet is required to create vNet.
    • vNet exists with subscription and region and cannot span subscription or region. There is limit for vNet soft limit =50 and hard limit = 500.
    • Routing between subnet in vNet is automatic and enabled by default using System Routes. System route cannot be modified or deleted, but we ca override it using custom route. 
    • Traffic from vNet to azure service is routed via Azure’s backbone network. Rest other traffic (except RFC 1918, RFC 6598) are routed via public internet 
  2. Route table. 
    • Route table are used to route traffic between vNet or another network. 
    • It contain 3 important information, source, destination and next-hop
      • Source = defines who created route (Default / system << Virtual Network Gateway / BGP << UDR (User defined route)
      • Destination : Subnet of destination network
      • Next-hop: 1st hop to reach destination network.
    • Most specific / longest prefix route is preferred, if there are multiple route to same destination than preference is (UDR >> Virtual Network Gateway >> System)
    • Next-hop type: 
      • Virtual network gateway
      • Virtual network (default Azure routing)
      • Internet
      • Virtual appliance (specified VM) 
      • None (black hole / drop traffic) 
  3. Network Security Group (NSG):
    • It acts like FW at network lever used to filter inbound / outbound traffic.
    • It is applied at VM (NIC) level or Subnet level.
  4. Service endpoint:
    • Allows communication from vNet to Azure service (e.g. blob service) 
  5. Application Security Group (ASG) 
    • Help to manage security of VM by grouping them according to the application that run on them. (e.g. Internet >>> webserver >>> app server >>> database server
  6. Azure Firewall and Azure Firewall manager 
    • Azure Firewall is firewall service from Azure and Azure Firewall manager is used to manage it.
    • Azure Firewall manager support secured virtual hub and hub virtual network. 
  7. Bastion host:
    • Node used as jump server, jump box or remote server host for client coming from internet.
  8. NAT Gateay
    • Network address translator 
  9. Azure DNS 
    • DNS service from Azure 
  10. Azure load balance. 
    • Used to balance network traffic / session load between group of servers.
    • There are public (external) and private (internal) load balancer. 
  11. Application Gateway : 
    • It works like L7 load balancer and can used path-based routing. 
  12. WAF (Web application Firewall) 
    • Used to protect web application use along with Application gateway.
  13. Azure traffic manager: a. Used as DR / HA solution to route traffic between different region.
  14. Express route:
    • Dedicated 10Gig connectivity to Azure cloud using private network via express route provider. 
  15. VPN Gateway: 
    • Allows to connect remote site (Site-to-Site) or user (Point-to-site) vpn 
  16. Local network gateway: 
    • Network object that represent on-premises location, used while configure VPN gateway.
  17. Virtual WAN
    • Form of HUB which allows to interconnect all vNet and on-premises site or remote user. 
  18.  vNet peering:
    • allows routing traffic between two vNet using Microsoft backbone network infrastructure
  19. Gateway transit:
    •  Allows vpn hub to forward traffic from spoke
  20. Azure FrontDoor: 
    • Microsoft global edge network that acts like entry-point to access hosted resource (Azure / on-premises) from public internet.
  21. Azure private link: 
    • Allow access to Azure service using private address space.
  22.  Azure private link service. 
    • Allows communication between resource from two vNet / network hosted in Azure using overlapping private ip

Saturday, July 31, 2021

Python Concept - Script, Module, library, function and classes

Important concept of Python 2021

Understanding Script, module, package,  library

·         Script: python file that run directly to perform certain task.

 

·         Module: Python file that is imported in script or another program. It defines member like classes, functions and variable intended to be used in other files that import it.

 

·         Python.org definition: An object that serves as an organizational unit of Python code. Modules have a namespace containing arbitrary Python objects. Modules are loaded into Python by the process of importing.

 

·         Package:  collection of related modules that work together to provide certain functionality. This are folder containing modules. It has special file with name __init__.py

 

·         Python.org definition : A Python module which can contain submodules or recursively, subpackages. Technically, a package is a Python module with an __path__ attribute.

 

·         To create Python package ourself, we have to create directory and a file named __init__.py inside it. This file cab be empty.

 

·         Note: Directories without an __init__.py file are still treated as packages by Python. However, these won’t be regular packages, but something called namespace packages.

 

·         In general, submodules and subpackages aren’t imported when you import a package. However, you can use __init__.py to include any or all submodules and subpackages if you want.

 

·         Library: a bundle of code / collection of packages. E.g. Matplotlib (plotting libaray)

o   Standard library (available by default)

o   3rd-Party Modules

 

 

Understanding import methods / option:

It is python keyword to make code in one module available in another. They help to structure code.

 

Method 1: Basic import:

Here pi is variable in math module.

Math acts as namespace (In computing, a namespace is a set of signs (names) that are used to identify and refer to objects of various kinds. )

To see content of math module you can use dir(math)

 

Method 2: import specific part (objects) from module

 

 

Method 3: import with rename

 

Importing module gives access to its objects using syntax: module.object

 

 

 

Method 4: Relative import.

From . import <sum-package-name>

The dot refers to the current package, and the statement is an example of a relative import. You can read it as “From the current package, import the subpackage <sum-package-name>”

 

 

 

Method 5 absolute import:

From math import pi

 

The PEP 8 style guide recommends using absolute imports in general. However, relative imports are an alternative for organizing package hierarchies. For more information, see Absolute vs Relative Imports in Python.

Don’t use from <module> import *

 

Python import path:

You can inspect Python’s import path by using sys.path.

 

List will contain three different kinds of locations:

·         The directory of the current script / current directory

·         The contents of the PYTHONPATH environment variable.

·         Other, installation-dependent direcotires.

 

Note 1: clearing import catch

Modules are cached, if we update module then we need to re-import it in old session and delete old cache.

That can be done using

Reload(<module-name>)

 

For Python3 (its not available by default)

Import  importlib

Importlib.reload(<module-name>)

 

Note 2:  __main__

Sometimes we want code to be executed when module is run directly , but not when it is imported by another module.

If  __name__ == ‘__main__’   allows us to check whether the module is being run directly.

 

 

 

Understanding function, class

Function is set of code that can be called repeatedly

 

 

What is Class ?

Object oriented programming (OOP):

OOP terms:

·         Class

·         object

Object has two parameters:

1.    Attributes (data / properties e.g. age, name etc)

2.    Behaviors (action walking, talking etc)

 

E.G. phone is object, but its design is class and object is instance.

Object is instance of class.

Function is OOP is called method.

 

 

·         Class can be considered as template for creating object with related data (attributes) and function (action) that do interesting thing with that data.

 

·         Class help to create customized data type

 

·         Function inside the class is called method.

 

·          

 

 

# Creating class Example 1

Class User:

     Pass

 

Note: pass is a sort of place holder.

 

Creating object

# User1

 

User1=User()

 

# Creating class Example 2

 

 

 

 

 

 

 

 

To use instance variable inside class function we can use self.<instance-variable-name>

 

 

Creating class with variable Example #3

Class Router:
    ‘’’Router Class’’’
    def __init__(self,model,swversion,ip_add):
        ‘’’initialize values’’’
        self.mode=model
        self.swversion=swversion
        self.ip_add=ip_add

 

 rtr1=Router(“ios”,”15.6.7”,”10.10.10.1”)

 

Function __init__  is called dunder or magic methods.

To store attributes we map the name self and the value you pass to it become variables inside the object, which is then store those value as attributes.

 

>>> rtr1.model

ios

 

We can define additional variable later.

>>> rtr1.desc =”virtual router”

>>> rtr1.desc

“virtual router”

 

Inheritance in Python classes allow a child class to take on attributes and methods of another class.

Class Switch(Router):

Here class Switch inherits the attribute of parent class Router.

 


 


 

 

 

Killing window application via python

Import os

os.system("taskkill /f /im notepad.exe")
os.system("taskkill /f /im winword.exe")
os.system("taskkill /f /im excel.exe")
os.system("taskkill /f /im powerpnt.exe")
os.system("taskkill /f /im outlook.exe")
os.system("taskkill /f /im chrome.exe")
os.system("taskkill /f /im calc.exe")
os.system("taskkill /f /im iexplore.exe")
os.system("taskkill /f /im powershell.exe")
os.system("taskkill /f /im wordpad.exe")