VPN connection check and if disconnected then connect

Hi,
I want to check the VPN is connected or not if not then i want to connect by providing the username and password.

Please guide me how to automate the task.