Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

parsing output from ping - python

import re
import subprocess
import sys

from tabulate import tabulate


def main():
    address = sys.argv[1]
    pingthis = ['ping', '-c', '1', address]
    r = (
        subprocess
        .run(
            pingthis,
            stdout=subprocess.PIPE,
            check=True,
        )
        .stdout
        .decode('utf-8')
    )
    table = tabulate(
        [[address, (re.search(r'time=(d+)', r).group(1))]],
        headers=["IP", "TimeToPing (ms)"],
        tablefmt="simple",
    )
    print(table)


if __name__ == "__main__":
    main()
Comment

PREVIOUS NEXT
Code Example
Python :: python extract multiple values from a single cell in a dataframe column using pandas 
Python :: opencv2.3 
Python :: map reduce and filter functions in python 
Python :: django.db.utils.ProgrammingError: (1146 
Python :: merge csv files into one 
Python :: pandas select random entry after groupby 
Python :: selsearch 
Python :: block-all-mixed-content csp bypass python 
Python :: find sum of all elements in a matrix by python 
Python :: DOWNLOAD ANALYZE_DXP.PY 
Python :: sklearn encoding pipelin 
Python :: cuenta atras segundero python 
Python :: typing effect python 
Python :: dataframe get missing and zero values 
Python :: knn.score sklearn 
Python :: ring Access List Items by String Index 
Python :: easy ocr python pypi 
Python :: python run unix command 
Python :: python adx indicator 
Python :: python netcdf double 
Python :: player to walk on the surface 
Python :: How to play audio in background 
Python :: get picamera feed 
Python :: python making player equipment 
Python :: add values to pandas plot 
Python :: count upercase 
Python :: python run async function without await 
Python :: http response template 
Python :: jumpssh execute multiple commands 
Python :: open pdf from pyqt in the same folder 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =