Step-by-Step Guide: Ping a Router Through Python Script

Network automation is becoming an essential part of computer networking. With the help of network automation, we use software to automate our daily tasks through Python script. Network automation helps us to configure our network from a centralized location. Here, we will write a script and then implement it on the networking device. We will use GNS3 software to simulate the automation script. We have already published an article on connecting GNS3 to a real network or laptop. So, if you don’t know how to connect GNS3 to a laptop, then first see that article and then apply this. This article will explain a Step-by-Step Guide on Ping a Router Through Python Script.

Ping

The ping command is used to test connectivity between the two nodes. First, we will use a ping script to test connectivity between our laptop and GNS3 routers R1 and R2. We will explain a Step-by-Step Guide on ping script, through which we will ping a router. The router R1 Fast ethernet 0/0 IP address is 192.168.20.5/24 while the Laptop IP having Ethernet 5 network adapter IP address is 192.168.20.6/24.

Ping a router through python script

Assign an IP address to the network adapter (ethernet 5) on a laptop or PC, as shown below in the screenshot. The default gateway is the Router R1 interface fast ethernet 0/0 IP address.

check ethernet 5 IP

Configure IP address 192.168.20.5/24 on Router R1 Fastethernet 0/0 interface.

Set router IP

Ping Router R1 from the Laptop or PC command prompt to check connectivity. Write a command “ping 192.168.20.5”, to check connectivity between GNS3 router R1 and Laptop or PC.

ping the GNS3 router

As the Ping was successful, write a Python script to Ping the GNS3 router R1 to check a script whether it is working or not.

python script for ping

The next phase is to save the script. I saved the script in the below screenshot path via ping1 name.

Note:I faced an issue, but I’m not sure if you will too. When I saved the Python script file at another location, then it wouldn’t run. But, when I saved it at the current location, then I ran.

save the script

Now open the CMD and run the script through the py command, followed by the script name. Go to the specified directory through the CD command. CD command is used to go from one directory to another directory. Run the Python script via the py command, followed by the script name.

Run the script

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *