Python Language for Network Professionals in the Tech Industry: A Comprehensive Guide to Computer Networking and Telecommunication Engineering.

This blog intends to provide a comprehensive understanding of the benefits and importance of Python for network professionals in the tech industry and the usecase.

Python is a high-level, object-oriented, interpreted language widely used for scripting and automation. It is easy to learn, integrates well with multiple platforms, and has a vast range of libraries and tools designed for network programming and automation. The blog explores the basics of Python, the various libraries and tools available for network programming, and provides real-world examples and case studies of Python implementation in networking. It highlights how Python can be used to automate network configurations, monitoring, troubleshooting, and cloud networking. Whether you are a network engineer, network administrator, or computer science graduate, understanding Python and its application in network programming can greatly enhance your career in the tech industry.

Why Python for Network Engineers?

Why Python for Network Engineers? Python is a versatile language that has become a choice for many network engineers in recent years because of its capabilities in automation, data parsing, and manipulation. Learning Python for networking opens up a variety of opportunities for network engineers and administrators alike, allowing them to automate complex tasks, configure networks with ease, and boost network efficiency. Automation Benefits As automation is becoming more ubiquitous in the IT industry, network engineering is no exception. By leveraging Python, network engineers can automate tasks that would otherwise be time-consuming and tedious if done manually, such as configuring devices, running backups, and monitoring network performance. Python makes automation efficient and straightforward by providing libraries and modules tailored explicitly for network automation. By building Python scripts, network engineers can automate repetitive tasks, reduce the risk of human errors, and focus on more critical tasks. Python Libraries for Networking Python libraries tailored for networking offer a high level of abstraction that simplifies typical network tasks, making them more manageable. Some of the libraries used in Python for networking include Netmiko, Nornir, Paramiko, and many others. Netmiko, for example, is a multi-vendor library that provides secure connections and the ability to execute commands over network devices. Nornir, on the other hand, is a Python automation framework that integrates various automation tools in a single platform, making it easier to manage large-scale networks. Examples of Network Automation Python for Network Engineers offers a vast range of opportunities for automating network workflows. One example of network automation is the configuration of firewalls, routers, and switches in an organization. By automating the configuration process with Python, network engineers can ensure consistency across network devices, eliminate human errors and reduce configuration time. Another example of automation is network monitoring. Network traffic data can be collected with Python by leveraging APIs offered by various network devices, and alerts can be generated to notify network administrators when user-defined thresholds are breached. Python’s capabilities in automation, data parsing, and manipulation allow network engineers to build systems that are more reliable, efficient, and scalable. In conclusion, Python for Network Engineers is a high-value skill in today’s job market. Python provides new opportunities for network engineers to automate, manage and design large-scale networks. By leveraging Python, network engineers can reduce their workload and increase efficiency while ensuring network consistency, minimizing human errors, and reducing configuration time.

Getting Started with Python for Networking

Python has been a popular choice for network professionals for some time now. With its powerful libraries and easy-to-use syntax, it has quickly become the go-to language for anyone involved in computer networking and telecommunications engineering. In this section, we will discuss the key points for beginners looking to get started with Python for networking, including Python installation and setup, Python modules for networking, and SSH and Telnet connection. First things first, you need to install Python on your system to start working with it. You can download the latest version of Python from the official website and install it on your computer. Once installed, you can use any IDE (Integrated Development Environment) to write Python code. PyCharm and Visual Studio Code are two popular IDEs used by network professionals for writing Python code. Python has an extensive library of modules that can be used for networking tasks. Some of the popular modules include ‘socket’ for creating network connections, ‘os’ for executing system commands, ‘subprocess’ for managing system processes, ‘threading’ for managing threads, and ‘multiprocessing’ for managing multiple processes. These modules make it easy to work with complex network configurations and automate various tasks. SSH and Telnet are two popular protocols used for remote access to network devices. Python provides a number of modules that can be used to automate SSH and Telnet connections. One such module is ‘Paramiko,’ which is often used by network professionals for SSH connections. For Telnet connections, the ‘Telnetlib’ module is recommended. With these modules, you can easily automate access to devices and execute remote commands. In addition to these modules, there are also several third-party libraries available for network automation. Netmiko and Nornir are two popular libraries used for network automation in Python. Netmiko is a multi-vendor library that can be used to automate the configuration of network devices from a wide range of vendors including Cisco, Juniper, and more. Nornir, on the other hand, is a Python framework that can be used to automate a wide range of network tasks, including configuration management, compliance auditing, and more. Networking tasks often involve parsing and manipulating data, and Python provides many useful modules for working with different kinds of data. For example, JSON and XML data can be easily parsed using the ‘json’ and ‘xml’ modules respectively. Regular expressions are another powerful tool for parsing data in Python. The ‘re’ module provides support for regular expressions in Python and can be used for complex data parsing tasks. In conclusion, Python is an essential tool for network professionals and is commonly used for automating network configurations and managing infrastructure. With its powerful libraries and easy-to-use syntax, it’s easy to get started with Python for Networking. By mastering the core concepts of Python and familiarizing yourself with the many libraries and modules available, you can become a proficient network professional in no time. So, if you haven’t already, it’s time to get started and take your network automation skills to the next level!

Python Libraries for Network Automation

Python Libraries for Network Automation When it comes to network automation, Python is the go-to programming language for network engineers. However, doing all the automation work from scratch can be a tedious task. This is where Python libraries come into play. Python libraries provide pre-written code and functions that can be integrated into your program to automate network tasks. Here are some of the most commonly used Python libraries for network automation:

Netmiko: Netmiko provides multi-vendor support for various networking devices, including routers, switches, and firewalls. It simplifies the process of working with network devices by providing a standardized command structure, which can be easily used across different vendors.

Nornir: Nornir is another popular Python library for network automation. It allows network engineers to write code that interacts with multiple devices simultaneously, making it an ideal choice for large-scale network automation projects.

Paramiko: Paramiko is a Python implementation of the SSH protocol, which allows Python scripts to connect to remote hosts securely. It provides support for SSH, SCP, and SFTP protocols, making it an ideal choice for automating tasks that require secure remote access. These libraries can significantly reduce the time and effort required for network automation. By using these libraries, network engineers can focus on creating new features and functionality, rather than spending time on mundane tasks.

So, if you’re a network engineer looking to automate network tasks, start exploring these Python libraries. They’ll not only simplify the task at hand but also make it more efficient and error-free.

Data Parsing and Manipulation using Python

As a Network Engineer, having to manipulate and parse data is a part of the daily tasks and automation benefits cannot be overemphasized. Python offers several built-in modules and tools for data parsing and manipulation. JSON and XML are two popular data formats used for exchanging data over the web. Python has built-in modules such as json and xml.etree.ElementTree for parsing and manipulating both formats, respectively. With the json module, it is easy to convert JSON formatted data into Python objects. The data can then be manipulated using standard Python operations. The xml.etree.ElementTree module also provides similar functionality for working with XML. Manipulating and filtering data can also be achieved using regular expressions. Python has a built-in module called re that provides support for regular expressions. Regular expressions provide a powerful and flexible way to search and manipulate text. It can be used to search, match, and replace text based on specific patterns. It is an essential tool for data extraction and cleansing. In addition to parsing and manipulating data, Python provides tools for data visualization. The Matplotlib library is a popular Python library that creates static, animated, and interactive visualizations in Python. It provides a wide range of plots such as Line plots, Scatter plots, Bar plots, Histograms, 3D plotting, etc. This library is an essential tool for creating reports and presenting data to stakeholders. In conclusion, Python provides an excellent set of tools for parsing, manipulating, and visualizing data. With built-in modules such as json, xml, and re, it makes it easy to work with popular data formats and can be used for data extraction and cleansing. Additionally, with the Matplotlib library, it is easy to create visualizations and generate reports. As a Network Engineer, knowing how to work with data is an essential skill, and Python makes it easier.

Python Frameworks for Network Automation

Python Frameworks for Network Automation Apart from the Python modules that we have discussed so far, there are also other Python frameworks that network engineers can use for network automation. These Python frameworks offer a higher level of abstraction and can help you automate network-related tasks more efficiently.

Ansible: Ansible is a popular Python framework designed for infrastructure automation. It’s agentless and doesn’t require any additional software or firewall ports opened on the network devices. Ansible can help you automate network configuration, orchestration, and deployment tasks. It uses a simple and human-readable language called YAML to define configuration files. This makes it easy to learn and use, even for non-programmers.

Chef: Chef is another Python framework designed for infrastructure automation. It’s a powerful solution that can help you automate network-related tasks as well as application deployment and management. Chef uses a declarative language to define infrastructure as code. This language is called Ruby, but Chef also supports YAML and JSON formats. Chef can be a bit complex and may require more setup and configuration than Ansible. However, it’s a great option for larger and more complex networks.

SaltStack: SaltStack is a Python framework that focuses on remote execution and configuration management. It’s designed to manage large-scale networks and can help you automate various network tasks, including configuration management, event-driven automation, and remote execution. SaltStack uses a YAML-based language called Salt State to define infrastructure as code. It also supports a variety of different languages, including Python, for custom extensions. In conclusion, these Python frameworks can help you automate and streamline network-related tasks, making your job easier and more efficient. Depending on your network’s size and complexity, one of these frameworks may be a better fit than the others. It’s worth exploring each of them in more detail to see which one would work best for your organization. Happy automating!

Case Studies: Real-world Examples

When it comes to network engineering, Python language is a real game-changer. It offers unparalleled flexibility, making time-consuming tasks such as network monitoring, troubleshooting, configuration, and management easy and fast. Here are some real-world examples of how Python can be used in network engineering to create a faster and more efficient network.

Network Monitoring and Troubleshooting

Monitoring network traffic and identifying traffic patterns is critical for network engineers. With Python, monitoring traffic becomes a breeze, and the results can be presented in easy-to-understand visuals. It’s possible to develop a program that identifies traffic spikes, traces the source, and gives real-time analysis of bandwidth usage. Python can also be used to create programs that analyze log files, identifying patterns and error messages more effectively than traditional network management systems.

Automated Configuration and Management

Automation is a game-changer in network engineering, and Python offers the tools to automate mundane, repetitive tasks both in configuration and management. Network discovery, which involves identifying devices, mapping the network topology, and obtaining network metadata, can be automated using Python. When it comes to configuration, Python scripts can handle mass upgrades and repetitive changes without any margin for errors.

Cloud Networking with Python

Networking in the cloud era can be challenging, but this is where Python comes into play. Python provides a rich suite of libraries and frameworks tailored to cloud computing. Using Python scripts, network engineers can automate cloud deployments, auto-scaling, auto-recovery, and auto-termination of resources. Cloud networking with Python removes the manual overhead associated with launching, configuring, and integrating cloud resources.

In conclusion, Python has become a must-have skill for network engineers. Its reliability and flexibility make repetitive tasks such as network monitoring, troubleshooting, configuration, and management much more accessible and can save teams many hours of work. The automation benefits, network libraries, and extensive frameworks make Python the right language for this role. By learning Python, network engineers can streamline their network procedures, which puts them in the best position to grow their careers in the tech industry.

Conclusion

Engineering has been thoroughly discussed in this blog. With Python being a core skill for network engineers, there is a need to depict its benefits and how to learn it. In summary, Python is an efficient programming language that makes automating complex systems easy while minimizing human errors. With its versatile nature, it can be used in network configuration, API integration, data parsing and manipulation, and it’s preferred by Cisco as the language of choice for their DevNet certifications, making it an essential skill for network professionals to learn. To get started with Python for networking, you would need to download and install Python, choose Python modules for networking such as SSH and Telnet and select a library such as Netmiko or Paramiko for automation. To learn Python for Networking, online courses are available. Every network engineer should embrace Python for automation especially in troubleshooting, and network monitoring.

Finally, it’s critical to stay up-to-date with Python frameworks such as Ansible, Chef and SaltStack. In conclusion, with Python’s comprehensive use in network programming, the benefits of learning Python for network professionals cannot be overemphasized. It’s time for network professionals to take advantage of Python to automate their systems and make managing infrastructure easier.

Credit: Written with the help of AI.

Linux integrated in Windows 10!!? learn how to open…

Windows Subsystem for Linux Version 2 (WSL 2) is built on the work done with WSL version one, but rather than using a translation layer between Linux and Windows, it uses virtualization technology to allow you to run lightweight virtual machines directly on windows 10. Microsoft has changed dramatically over the last few years.  They have purchased GitHub, they do a lot of work in the cloud and now they have given you a Linux kernel directly into windows. This makes it very easy for you to learn Linux, allows you to run a Windows operating system but still develop on Linux if you want to. It is very tight integration between WSL version two and windows 10.

In this walkthrough, I am going to use windows 10 pro edition but you can use Windows 10 Home edition too, it works just fine. But the only requirement is that you need to update your windows 10 to the latest release.

How to enable this:

Once you have updated your windows Operating System to the latest release, it is very simple to enable this. You need to go to “Turn Windows features on or off” from control panel or from start menu, search the item and click. From there all you are going to need is to enable “Virtual Machine Platform” and “Windows Subsystem for Linux” options as shown in the below image.

Make sure that you enable both of these options. You don’t need to enable Hypervisor Platform as it is only windows 10 that you use in your laptop or desktop. Click Ok and windows will apply the changes. It requires you to reboot your computer.

Install your Linux distribution of choice from Microsoft Store. The following links will open the Microsoft store page for each distribution:

In this case, i will be installing latest Ubuntu 20.04 LTS distribution. So, after computer has rebooted, go to the Microsoft Store from Start menu and search for Ubuntu. You can find several Ubuntu releases, so, it’s up to you which version you want to use. Latest Ubuntu released 20.04 LTS in April 2020. Once it is downloaded then click Launch.

A command prompt like window will appear titled “Ubuntu 20.04 LTS” and it will show “Installing, this may take a few minutes…”

Once completed it will prompt for UNIX username. Note that the username does not need to match your Windows username.

So, give a username and password as you like. Now you will be logged into a Linux shell and you can use any Linux command as you do on any Ubuntu Machine.

You can start the Ubuntu machine anytime by clicking start menu or windows search button on the bottom and typing ubuntu, like any other app on windows machine, you can just open the Ubuntu shell and start using. You can use “lsb-release -a” command to check/confirm the release version.

The great thing about WSL is that it is very tight integration between Windows and WSL. If you want to learn Linux, this is a great way to start. One of the advantages of WSL version two is that it boots up very quickly and gives you a “shell” than other dual OS technique line VMware/Hyper-V/V-Box.

Another great advantage of using WSL is that you can use windows application like Visual Studio Code to edit Ubuntu files directly from Windows 10. Isn’t it awesome? So, what’s holding you back now. Start learning Linux from Microsoft provided Subsystem!!…

ssh to cisco router with python cmd script and save to file.txt

Python is a strong language to do any thing you want. If you want to make a program which will take router backup in a file with scheduled time. You can also use current date as concurrent with file name.

First you need to import “paramiko” library for ssh client.

You can also import datetime for naming the file with creation date.

Use below py codes which is complete with file output in the same directory. You can change the directory if you want.

import paramiko
import datetime


ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())


hostname = '192.168.200.2'
username = 'noc'
password = 'noc123'
port = 22


ssh.connect(hostname, port, username, password, look_for_keys=True)

stdin,stdout,stderr = ssh.exec_command('show run')
output = stdout.readlines()


date = datetime.datetime.now()
f = open('Core-01__'+date.strftime("%d %B %Y")+'.txt','w')
f.write(''.join(output))
print('Write successfull')
f.close()

Above python script will use ssh to login to router having IP 192.168.200.2 with user noc and password noc123. it will write “show running-config” to a file named “Core-01__date”.

Hope you will find this useful.

SCP file transfer between two linux machine in command line

SCP (Secure Copy) is a command line tool for Linux systems to securely transfer files from local to remote server or vice a versa. SCP uses SSH protocol for transferring files between two systems which is more secure than ftp.

Syntax: (Local to Remote)

scp /path/to/local/file.txt user@192.168.10.100:/remote/path/

Syntax: (Remote to Local)

scp user@192.168.10.100:/remote/file.txt /path/to/local/

SCP command required password of remote system. In case you need to configure scp command in script and run with scheduler, you need to configure key based ssh login.

Transfer File Local to Remote Server
Following command will copy myfile.txt from current directory of local system to remote server’s /opt directory using root authentication. We are assuming remote server hostname is example.com.

$ scp myfile.txt root@example.com:/opt/

Transfer File Remote Server to Local
Following command will copy /opt/myfile.txt from remote system to local system’s /opt directory.

$ scp root@example.com:/opt/myfile.txt /opt/

Define Port with SCP Command
In case SSH is running on different port on remote server, use -P switch followed by port number with scp command.

$ scp -P 2344 myfile.txt root@example.com:/opt/myfile.txt

Transfer Directory Local to Remote Server Recursively
Following command will copy /opt/mydir directory from local system to remote system’s /opt directory recursively.

$ scp -r /opt/mydir root@example.com:/opt/

Transfer Directory Remote Server to Local Recursively
Following command will copy /opt/mydir directory from remote system to remote system’s /opt directory recursively.

$ scp -r root@example.com:/opt/mydir /opt/

CentOS 7 no interface, no internet! installed on VMware workstation.

Job for network.service failed because the control process exited with error code.

This is what CentOS 7 says while you are trying to restart network.servce. New bees always runs into this problem i think atleast once. Because it was me too. So here i’m writing an easy solution.

When you ran into this problem your “ifconfig” command will only show you “l0” and/or “virbr0” in the list. There is no “eth0” or “eno16777736” device there. Then it must be giving big pain to your head.

Use below command …

dhclient -v

It will bound some IP address to the interface, its taking IP from DHCP, output will look something similar like below…

[root@localhost Desktop]# dhclient -v
Internet Systems Consortium DHCP Client 4.2.5
Copyright 2004-2013 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/virbr0-nic/52:54:00:2e:2f:5f
Sending on LPF/virbr0-nic/52:54:00:2e:2f:5f
Listening on LPF/virbr0/52:54:00:2e:2f:5f
Sending on LPF/virbr0/52:54:00:2e:2f:5f
Listening on LPF/eno16777736/00:0c:29:bd:5c:3f
Sending on LPF/eno16777736/00:0c:29:bd:5c:3f
Sending on Socket/fallback
DHCPDISCOVER on virbr0-nic to 255.255.255.255 port 67 interval 4 (xid=0x7cc5ba1e)
DHCPDISCOVER on virbr0 to 255.255.255.255 port 67 interval 3 (xid=0x47fa961e)
DHCPREQUEST on eno16777736 to 255.255.255.255 port 67 (xid=0x426c09a9)
DHCPACK from 192.168.237.254 (xid=0x426c09a9)
bound to 192.168.237.128 -- renewal in 683 seconds.

And Boom!!! your VM machine will have internet again… you can create a file with this command and make it auto start in boot. then you dont have to do this again and again…

Thanks!!!

Bootstrap

INTRODUCING BOOTSTRAP

Bootstrap is an open-source framework used to develop websites based on HTML, CSS and JavaScript, Bootstrap started as a project by Mark Otto and Jacob Thornton. The intention was to encourage consistency across web pages, but grew to include tooling for mobile-first design and common features web developers want, such as validation and dialog boxes.

Less is a style sheet language that helps overcome some of the complexities and shortcomings with CSS, and is converted into CSS that browsers can use. Bootstrap uses it because the Less is converted to CSS, developers using Bootstrap do not need to be familiar with Less. However, knowing Less can make customizing sites easier.

Bootstrap offers web developers many advantages. It makes it easier to layout pages without the use of tables. It simplifies CSS, as the bulk of the functionality you look for as a developer is already built for you, and frequently only requires the addition of classes to HTML elements, and a bit of structure.

There are several tools that make development with Bootstrap even easier. Visual Studio has IntelliSense for Bootstrap, which offers autocompletion of the different classes. You can also download a set of snippets for Visual Studio, which allows you to create complex Bootstrap structures with just a couple of clicks of the mouse.

CREATING A BOOTSTRAP ENABLED PAGE

I assume that you are familiar with HTML(Hyper Text Markup Language) already and also CSS. As you can edit or create HTML with any text editor Bootstrap is also like that. But first you need to add necessary file references in HTML like CSS.

Regardless of the editor you choose, and you can use any editor you like, the steps to add Bootstrap to a page are similar.

  1. Otain the necessary files
    To add Bootstrap to a page, you’ll need to obtain the CSS, glyphicons, and JavaScript files from www.getbootstrap.com. These files are available in a single zip file, which can be extracted to the folder you’ll store your HTML pages in. By default, the folders inside of the zip file are titled css, fonts and js. While you can keep these folder names, I like to rename css to Styles, and js to Scripts.
    In addition, the Bootstrap JavaScript library requires jQuery. You can obtain jQuery from www.jquery.com. The only file you’ll need is the minified, production file. You can add this to the Styles folder.
  2. Create an HTML page and add the necessary references
    After creating an HTML page, you need to reference the following files:

    1. Inside the head section, create a reference to bootstrap.min.css. Sample HTML for creating the reference is provided below. Remember, if your CSS file is in a different folder, you will need to update the folder name Styles to the name you chose. (In addition, you could use a content delivery network (CDN)).
      <link rel='stylesheet' href='./Styles/bootstrap.min.css' />
    2. Inside the body section, typically at the bottom, you need to reference two JavaScript files, jQuery and Bootstrap. The files must be referenced in that order. As before, you will need to update the folder name Scripts to the name you chose. The name of the jQuery file may also be different as the version of jQuery changes over time. Finally, you could also use a CDN to serve the necessary files.
      /Scripts/jquery-2.1.4.min.js and /Scripts/bootstrap.min.js

When referencing script or CSS files, best practice is to use the minified versions of the files, typically identified with the letters min in the name. Minified files don’t contain line breaks, spaces, or other components that make the scripts human readable, things which browsers don’t need. By using the minified versions, you minimize the amount of data sent to the client, which will improve the rendering speed of the page.

On the next post we will continue with bootstrap classes and work with a page design practically.

Break Root Password

How to break root password in Linux (RedHat/CentOS)

Its actually very easy to break a linux server’s root password if you have access to the physical server. Security is actually an illusion, just you need to make your server secure from any kind of threat that is coming from your environment and also your friends.

Here i will describe how to break a linux server’s password in a easy way, if you anyhow forget your root password it can be recovered just some few steps and commands. lets begin…

Step-1: Reboot your system by hard switch or pressing ‘Ctrl+Alt+Del’ or any other way you want. And don’t allow your server to load the OS again, i mean before loading just press arrow keys.

Step-2: Now you need to edit the current entry by pressing ‘e’ button. It will open some scripts in your window.

Step-3: Find the line that starts with ‘linux16’ and navigate your cursor to the end of the line. You can do this by pressing the ‘End’ button or by pressing right arrow until the last character. Now add or append ‘rd.break’ after a space at the end of the line. And press ‘Ctrl+x’ to boot using the modified config.

Step-4: System will appear with command link viewing something like below.

switch_root:/#

Now you need to remount /sysroot file and give read/write permission.

switch_root:/# mount -o remount,rw /sysroot

Step-5:

switch_root:/# chroot /sysroot

‘chroot’ runs a command or an interactive shell from another directory, and treats that directory as root. It will take you to a new shell like below.

sh-4-2#

Step-6:

Here you need to give the ‘passwd’ command to give it a new password. it will prompt twice.

sh-4.2# passwd [press enter]

: ******* (123456)
: ******* (123456)

Step-7:

After all these steps the last step is to create a autorelabel executable file which the OS will take to relabel the configuration file. Next just exit from both shell and it will take some time(like 2min) to boot and you can enter with the new password.

sh-4.2# touch /.autorelabel
sh-4.2# exit

switch_root:/# exit

Wait for 2 minute and Login… Hurreeeh…!!! now access the root with your new password and you can change this with any password you want.

Hello World!!!

I am wondering why each and every programming code tutorials starts with writing “Hello World”. It could be anything. Hello world is just a simple string and it used to show some thing as output.

Below i am listing the way of different programming languages to print/show the “Hello world” string…

python:

print(“Hello world!”)

C#:

console.writeline(“Hello world!”);

C/C++:

printf(“Hello world!”)

html:

<html><body>Hello World!</body></html>

php:

<?php
echo “My first PHP script!”;
?>

p