Home 0P3N Blog Ping Using Python Script
Ready to Start Your Career?
Create Free Account
Amine Essiraj - 4m1n3 3551r4js profile image
By: Amine Essiraj - 4m1n3 3551r4j
January 18, 2017

Ping Using Python Script

By: Amine Essiraj - 4m1n3 3551r4j
January 18, 2017
Amine Essiraj - 4m1n3 3551r4js profile image
By: Amine Essiraj - 4m1n3 3551r4j
January 18, 2017
Estimated reading time: 1 minute

Hello Cybrary Community,This is my first little article on Cybrary, and as the title says, I'll show you how to create your own Ping tool with a simple script using Python. So, what is Ping? According to WikiBooks, "Ping is a basic Internet tool that allows a user to verify that a particular IP address exists and can accept requests." Let's start writing our script for Ping:

  • import socket
  • import sys
  • s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  #Create a TCP/IP socket
  • server_ip = raw_input('Enter server IP : ')
  • rep = os.system('ping ' + server_ip)
  • if rep == 0:
    • print 'n n server is up n n'
  • else:
    • print 'server is down'

That's it! See, I told you it was simple. Happy Pinging :) Comment below if you have any questions, and thanks.

Schedule Demo

Build your Cybersecurity or IT Career

Accelerate in your role, earn new certifications, and develop cutting-edge skills using the fastest growing catalog in the industry