Solved

Connecting to VPN with a Batch file

Posted on 2010-09-18
9
1,537 Views
Last Modified: 2012-08-14
I have a batch file that I am passing parameters - it sets the username and password but the IKE connection fails - can someone check my batch file and tell me if it is correct?  also how can I tell what the value of the args are that are being passed to the console
any help would be greatly appreciated
@echo off

pushd "%programfiles%\checkpoint\securemote\bin"

if not exist scc.exe goto scc_missing

echo #### Setting command-line mode

scc.exe setmode cli

echo #### Setting login information


scc.exe userpass Username Password


echo #### Starting VPN connection

scc.exe connect -p Work

echo -

echo #### Testing connection

ping -w 1000 -n 4 10.10.0.18 > NUL

if errorlevel 1 echo Connection test failed!

if errorlevel 1 goto disconnect

if errorlevel 0 echo Connection tested OK!

:disconnect

echo -

echo #### Disconnecting..

scc.exe disconnect -p

echo #### Erasing login information

scc.exe erasecreds

echo #### Setting GUI (connect) mode

scc.exe setmode con

goto end

 

:scc_missing

echo #### SCC.EXE appears to be missing! Aborting..

goto end

 

:end

popd

echo #### Done!

pause

Open in new window

0
Comment
Question by:r3nder
  • 5
  • 4
9 Comments
 
LVL 5

Expert Comment

by:sosinc3
ID: 33710288
If you want to see what is happening during the running of this batch file either remove the first @ECHO OFF line or put REM (with a space after it) at the beginning of that line. That way you can see each line as it is getting processed. Also, you could insert several PAUSE commands throughout your batch file to make the process stop to see where it exactly is failing.
0
 
LVL 6

Author Comment

by:r3nder
ID: 33710317
This is what I get: - Is it saying the word Username and password were set or the username and password args were set

C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Setting command-line mode

#### Setting command-line mode



C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe setmode cli

Switched successfully to Command Line mode



C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Setting login information

#### Setting login information



C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe userpass YOURLOGIN YOURPASSWO

RD

Username, password were set.



C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Starting VPN connection

#### Starting VPN connection



C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe connect -p ETIHome

   Checking network connectivity...

   Preparing connection...

   Connecting to gateway...

   IKE negotiation failed

   Connection failed

Connect failed



C:\Program Files\CheckPoint\SecuRemote\bin>echo -

-



C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Testing connection

#### Testing connection



C:\Program Files\CheckPoint\SecuRemote\bin>ping -w 1000 -n 4 10.10.0.18  1>NUL



C:\Program Files\CheckPoint\SecuRemote\bin>if errorlevel 1 echo Connection test

failed!

Connection test failed!



C:\Program Files\CheckPoint\SecuRemote\bin>if errorlevel 1 goto disconnect



C:\Program Files\CheckPoint\SecuRemote\bin>echo -

-



C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Disconnecting..

#### Disconnecting..



C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe disconnect -p

Already disconnected



C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Erasing login information

#### Erasing login information



C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe erasecreds

Credentials were unset OK.



C:\Program Files\CheckPoint\SecuRemote\bin>echo #### Setting GUI (connect) mode



#### Setting GUI (connect) mode



C:\Program Files\CheckPoint\SecuRemote\bin>scc.exe setmode con

Switched successfully to Connect mode



C:\Program Files\CheckPoint\SecuRemote\bin>goto end



C:\Program Files\CheckPoint\SecuRemote\bin>popd



C:\Documents and Settings\Michael\My Documents\Visual Studio 2008\Projects\VPNTe

st\VPNTest\bin\Debug>echo #### Done!

#### Done!



C:\Documents and Settings\Michael\My Documents\Visual Studio 2008\Projects\VPNTe

st\VPNTest\bin\Debug>pause

Press any key to continue . . .

Open in new window

0
 
LVL 5

Expert Comment

by:sosinc3
ID: 33711452
In your batch file, you need to actually put the real username and the password so the line that now reads

SCC.EXE USERPASS YOURLOGIN YOURPASSWORD should be for example

SCC.EXE USERPASS sosinc3 secretpassword    assuming the username name was sosinc3 and the password was secretpassword.

0
 
LVL 6

Author Comment

by:r3nder
ID: 33711533
Yeah I figured how to pass that in last night - I used SCC.EXE USERPASS  Username= %1 password=%2
That passed the arguments to the batch file - now I have another problem - our company allows users to use special characters in their password. So I have to figure a way to pass the password with the special character as a set string. For example
Set Caret= ^^  
if Password=%2 = "^" set "^"
Not sure how to do it but - I am still looking
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 5

Accepted Solution

by:
sosinc3 earned 500 total points
ID: 33711649
just replace the line to read as follows:

SCC.EXE USERPASS %1 %2

Then when you run the batch file, lets assume it is called vpn.bat, you would type

vpn sosinc3 "secret$password&ofthe^day"

That works for me on my PC here.

0
 
LVL 5

Expert Comment

by:sosinc3
ID: 33711666
I clicked on submit too quickly. Note how I have the whole password in quotation.
0
 
LVL 6

Author Comment

by:r3nder
ID: 33712225
yes that worked - so what I am doing is in the windows form - I get the username and password - then when I pass the args from the form to the bat file I added
string args = @"/c VPN.bat " + Username + " " + '"'+ Password + '"';
and TADA! ......it worked - I guess I can leave it like that and no matter what is typed - So in password it will be sent using the double quotes
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 33712357
It was a pleasure to have learned from you
0
 
LVL 5

Expert Comment

by:sosinc3
ID: 33712707
No problem. I am glad I was able to help.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Juniper VPN devices are a popular alternative to using Cisco products. Last year I needed to set up an international site-to-site VPN over the Internet, but the client had high security requirements -- FIPS 140. What and Why of FIPS 140 Federa…
I recently attended Cisco Live! in Las Vegas, a conference that boasted over 28,000 techies in attendance, and a week of hands-on learning hosted by a solid partner with which Concerto goes to market.  Every year, Cisco displays cutting-edge technol…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now