need to run some prog whe i'm online

Hi
i use a lan and a modem ethernet
i’m looking for a program that is able to ping to detect if i’m online
and then runs my programs

help me