Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ping program in Python
#11
Can change to this then DeaD_EyE code work on Windows to,if someone try to run there.
privileged = os.getlogin() == 0
A test of async_ping in icmplib and run in schedule way with use of schedule.
from icmplib import async_ping
import schedule
import time
import asyncio

async def is_alive(address):
    host = await async_ping(address, count=4, interval=0.2)
    if host.is_alive:
        print(f'{host.address} is up!')
        print(host.packets_received)
        print(host.packet_loss)
    else:
        print(f'{host.address} is down!')
        # Do something here

def check_run():
    return asyncio.run(is_alive('python-forum.io'))

schedule.every(10).seconds.do(check_run)
while True:
    schedule.run_pending()
    time.sleep(1)
Output:
λ python ping_sc.py 104.21.27.41 is up! 4 0.0 104.21.27.41 is up! 4 0.0 104.21.27.41 is up! 4 0.0 104.21.27.41 is up! 4 0.0
Reply


Messages In This Thread
ping program in Python - by Skaperen - Mar-02-2022, 11:17 PM
RE: ping program in Python - by BashBedlam - Mar-03-2022, 03:10 AM
RE: ping program in Python - by ndc85430 - Mar-03-2022, 04:59 AM
RE: ping program in Python - by Skaperen - Mar-03-2022, 05:30 AM
RE: ping program in Python - by ndc85430 - Mar-03-2022, 06:25 AM
RE: ping program in Python - by snippsat - Mar-03-2022, 03:56 PM
RE: ping program in Python - by Skaperen - Mar-03-2022, 10:51 PM
RE: ping program in Python - by snippsat - Mar-03-2022, 11:43 PM
RE: ping program in Python - by Skaperen - Mar-04-2022, 02:54 AM
RE: ping program in Python - by DeaD_EyE - Mar-04-2022, 12:22 PM
RE: ping program in Python - by snippsat - Mar-04-2022, 03:13 PM
RE: ping program in Python - by Skaperen - Mar-04-2022, 08:27 PM
RE: ping program in Python - by snippsat - Mar-05-2022, 07:33 AM
RE: ping program in Python - by Skaperen - Mar-05-2022, 06:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  creapy ping Skaperen 0 1,879 Jul-04-2018, 02:55 AM
Last Post: Skaperen
  Can a python program execute an action on another software program? lex 4 4,050 Jan-26-2018, 03:10 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020