ping with python

Solutions on MaxInterview for ping with python by the best coders in the world

showing results for - "ping with python"
Spencer
28 Jan 2020
1from os import system
2print('1. Ping Google')
3print('2. Ping Yahoo')
4print('3. Ping custom URL')
5while True:
6    key = int(input('Input your choice: '))
7    if key == 1:
8            system("ping www.google.com")
9    elif key == 2:
10            system("ping www.yahoo.com")
11    elif key == 3:
12            url = input('Enter URL: ')
13            system("ping " + url)
14    else:
15            print("Invalid Option!")
16
Helena
23 Jan 2020
1import subprocess
2
3def main():
4    host = input("Enter Host: ")
5    packet = int(input("\nEnter Packet: "))
6    print("\n")
7    ping = subprocess.getoutput(f"ping -w {packet} {host}")
8    print(ping)
9
10main()