Question: Is there any efficient way to check and report in a log file or on the console may be... when ever the VPN is disconnected?

```
import time
print time.asctime( time.localtime(time.time()) )

```

Can print the time but I do not know what is the code to recursively find whether the VPN is active or not. Pinging it in a while(1) would be a stupid way to check if the connection is active or not. Any way to achieve this?

Answer: 
This solution is system dependent, I do know that it works on Linux because I've done something similar, but not sure about Windows though. I don't know if you want a solution not involving ping, but I think this is a good solution.

```
import logging, os, time

PING_HOST='10.10.10.10'  # some host on the other side of the VPN

while True:
    retcode = os.system('ping -c 1 %s' % PING_HOST)

    if retcode:  
       # perform action for lost connection
       logging.warn('Lost visibility with %s' % PING_HOST)

    time.sleep(10)  # sleep 10 seconds

```

This works because ping returns a return code of `0` for success. All other return codes signify an error.
This method uses the NAME of the HOST "Connection-specific DNS Suffix" associated with your IP (Mostly the corporation's VPN):

```
import os
import platform
def check_ping():
   hostname = "xyz.com" #hostname will be..Name under: "Connection-specific DNS Suffix" when you type "ipconfig" in cmd..
   response = os.system("ping " + ("-n 1 " if  platform.system().lower()=="windows" else "-c 1 ") + hostname)
   # and then check the response...
   if response == 0:
       pingstatus = "Network Active: Connected"
   else:
       pingstatus = "Network Error: Not Connected"

   return pingstatus
response = check_ping()
print(response)

```