ping with python

36

import subprocess

def main():
    host = input("Enter Host: ")
    packet = int(input("\nEnter Packet: "))
    print("\n")
    ping = subprocess.getoutput(f"ping -w {packet} {host}")
    print(ping)

main()
from pythonping import ping

def ping_host(host):
    ping_result = ping(target=host, count=10, timeout=2)

    return {
        'host': host,
        'avg_latency': ping_result.rtt_avg_ms,
        'min_latency': ping_result.rtt_min_ms,
        'max_latency': ping_result.rtt_max_ms,
        'packet_loss': ping_result.packet_loss
    }

hosts = [
    '192.168.48.1',
    '192.168.48.135'
]

for host in hosts:
    print(ping_host(host))

Comments

Submit
0 Comments