Connecting CiscoAnyConnectVPN via bash script in Windows
Cisco VPN
I hope everyone in the technical world would come across the word VPN and using it on the needed basics.
I have been using the Cisco AnyConnect as my primary VPN Client for more than a few months. The simple view of the client is really impressive and productive.
Whenever I want to connect to my VPN host following are the ideal steps that are followed/suggested as well
- Open CiscoAnyConnect VPN client
- Type VPN host address in the text of the VPN client and click connect.
- VPN Client will open the alert popup to select the type, username & password.
- Enter the details and press OK
- This will establish the VPN connection with the request address
The steps are easy when you are working with only one VPN connection but in most cases, it's not true. Earlier I had to work with 3 VPN connections for my work and later it had reduced to two, I need to switch between the VPN for my work.
I was checking this for a long time and I have got few leads based on that I have automated the connection.
Following are the steps to follow
- CiscoAnyConnect with CLI
- Create the simple batch script to connect
- Create Custom Run Command
CiscoAnyConnect with CLI
- Verify the CiscoAnyConnect CLI
- Navigate to the CiscoAnyConnect installation directory. The default directory would be C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client
- Open the Command Prompt in the current directory and execute vpncli.exe disconnect
- If you are seeing the following image then you are good to go, if not reinstall the CiscoAnyConnect
Create the simple batch script to connect
- Navigate to CiscoAnyConnect installation directory
- The default directory would be C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client
- Create a file based on the following template
Template File
connect <host>
[Optional: drop down selection]
<username>
<password>
Sample File
connect connect2vinoth.com
0
vinoth
openworld
4. Save the file in sample file format c2v.txt
5. Create the batch file connecting to connect2vinoth.com
Template
vpncli.exe disconnect > To disconnect the existing connection
vpncli.exe -s < filename.txt > To connect VPN via CMD
Sample
vpncli.exe disconnect
vpncli.exe -s < c2v.txt
Create Custom Run Command
Configure on System startup (If needed)
The easiest way to trigger scripts to run at startup is to drop them inside the startup folder.
To easily navigate to the startup folder, Windows has an alias available: shell:startup. Use shell:common startup
You can get to the startup folder a couple of ways:
Simply copy the files that you want to run on startup into the folder.
For example, in Windows 10, these paths work for me for the user and global:
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup
%ProgramData%\Microsoft\Windows\Start Menu\Programs\StartUp
I have tried these settings on my Windows 10 machine. It's working fine for me, you guys try it out and let me know your feedback in the comment section.
Key Take aways
Happy Coding!
Happy Working!!
Happy innovation!!!
Spread the Positivity around you
Comments
There are no comments for this story
Be the first to respond and start the conversation.