05 Nov 2010

Ping an Ip using python subprocess

No Comments Python


Another simple python module to test a ping return using Subprocess.

#!/usr/bin/python
"""
Description: This module tests a ping return
Author: Thiago de Freitas Oliveira Araujo

http://thiagodefreitas.com

thiago <at> thiagodefreitas.com

"""
import subprocess

class pingCommunication():

    def __init__(self, ipToPing):
        self.ipToPing = ipToPing
        self.pingQuantity = "1"

    def pingProcess(self):
        pingTest = "ping -c "+ self.pingQuantity + ' ' + self.ipToPing
        print pingTest
        process = subprocess.Popen(pingTest, shell=True, stdout=subprocess.PIPE)
        process.wait()
        returnCodeTotal = process.returncode
        print returnCodeTotal

if __name__ == "__main__":

    comunicate = pingCommunication("192.168.36.19")
    comunicate.pingProcess()

Related Posts

Tags: , , , , , ,

written by
The author didn‘t add any Information to his profile yet.
Related Posts
No Responses to “Ping an Ip using python subprocess”

Leave a Reply

*

WP SlimStat