Ping Using Python Script
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'
- 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.