Edit
Attach
Printable
topic end
<!-- * Set TOPICTITLE = #define private public - Claus Brod on stuff (20 Aug 2011) --> <style type="text/css"> pre {background-color:#ffeecc;} </style> %STARTINCLUDE% <a name="20"></a> ---+++ [[DefinePrivatePublic20110820JuniperNetworkConnect][Scripting VPN connections]] (20 Aug 2011) <summary> Like many other companies, my company provides VPN access to its employees so that we can stay connected from our home offices or on the road. Most of the time, I connect to the company network through a web portal which downloads, installs and runs <a href="http://www.juniper.net/us/en/">Juniper's</a> "Network Connect" software on the Windows client system. That's all fine and dandy, except that I am a command-line guy and find it _way_ too clumsy to fire up a web browser just in order to "dial in". </summary> Fortunately, Juniper's Network Connect client has a command-line interface, and so here is a trivial DOS batch script which can be used to establish a connection in "I-don't-need-no-stinkin'-buttons" mode. The script assumes that the Network Connect client has been installed and run in the usual manner (i.e. from the web portal) at least once. It will attempt to auto-detect the VPN host and user name, so in most cases all you have to specify is password information. Oh, and the script assumes you want to connect to the "SecurID(Network Connect)" realm by default, which requires entering a PIN and a number displayed on your RSA <nop>SecurID token. <style type="text/css"> <!-- pre { font-family: monospace; color: #000000; background-color: #ffeecc; } body { font-family: monospace; color: #000000; background-color: #ffffff; } .Todo { color: #0000ff; background-color: #ffff00; } .PreProc { color: #a020f0; } .Special { color: #6a5acd; } .Constant { color: #ff00ff; } .Comment { color: #0000ff; } .Statement { color: #804040; font-weight: bold; } .Identifier { color: #008080; } --> </style> <pre> @<span class="Identifier">echo</span><span class="Statement"> off</span> <span class="Identifier">REM</span><span class="Comment"> Launch Juniper Network Connect client from the command line</span> <span class="Identifier">REM</span><span class="Comment"> Written by Claus Brod in </span><span class="Constant">2011</span><span class="Comment">, see</span> <span class="Identifier">REM</span><span class="Comment"> <a href="http://www.clausbrod.de/Blog/DefinePrivatePublic20110820JuniperNetworkConnect">http://www.clausbrod.de/Blog/DefinePrivatePublic20110820JuniperNetworkConnect</a></span> <span class="Identifier">REM</span><span class="Comment"> --------------------------------------------------------</span> <span class="Identifier">setlocal</span> enableextensions <span class="Statement">call</span><span class="Statement"> :find_juniper_client</span> NCCLIENTDIR <span class="Statement">if</span><span class="Statement"> </span><span class="Constant">"x</span><span class="Identifier">%NCCLIENTDIR%</span><span class="Constant">"</span><span class="Statement">==</span><span class="Constant">"x"</span> ( <span class="Identifier">echo</span><span class="Constant"> ERROR: Cannot find Network Connect client.</span> <span class="Statement">goto</span><span class="Statement"> :end</span> ) <span class="Identifier">rem</span><span class="Comment"> CONFIGURE: Set your preferred VPN host here.</span> <span class="Identifier">set</span><span class="Identifier"> url</span><span class="Statement">=</span>define-your-vpn-host-here ping -n <span class="Constant">1</span> <span class="Identifier">%url%</span> >nul <span class="Statement">if</span><span class="Statement"> not errorlevel</span> <span class="Constant">1</span> <span class="Statement">goto</span><span class="Statement"> :validhost</span> <span class="Identifier">rem</span><span class="Comment"> Try to auto-detect the VPN host from the config file</span> <span class="Identifier">set</span><span class="Identifier"> NCCLIENTCONFIG</span><span class="Statement">=</span><span class="Constant">"</span><span class="Identifier">%NCCLIENTDIR%</span><span class="Constant">\..\Common Files\config.ini"</span> <span class="Statement">if</span><span class="Statement"> exist</span> <span class="Identifier">%NCCLIENTCONFIG%</span> <span class="Statement">for</span> <span class="Special">/f</span> <span class="Constant">"delims=[]"</span> <span class="Special">%%</span>A in (<span class="PreProc">'</span><span class="Identifier">findstr</span><span class="PreProc"> [[a-z0-</span><span class="Constant">9</span><span class="PreProc">]\. </span><span class="Identifier">%NCCLIENTCONFIG%</span><span class="PreProc"> ^| </span><span class="Identifier">findstr</span><span class="PreProc"> /V </span><span class="Constant">"Network Connect"</span><span class="PreProc">'</span>) do <span class="Identifier">set</span><span class="Identifier"> url</span><span class="Statement">=</span><span class="Special">%%</span>A ping -n <span class="Constant">1</span> <span class="Identifier">%url%</span> >nul <span class="Statement">if</span><span class="Statement"> errorlevel</span> <span class="Constant">1</span> ( <span class="Identifier">echo</span><span class="Constant"> ERROR: Host </span><span class="Identifier">%url%</span><span class="Constant"> does not ping. Please check your configuration.</span> <span class="Statement">goto</span><span class="Statement"> :end</span> ) <span class="Statement">:validhost</span> <span class="Statement">call</span><span class="Statement"> :read_no_history</span> url <span class="Identifier">%url%</span> <span class="Constant">"VPN host"</span> <span class="Identifier">set</span><span class="Identifier"> user</span><span class="Statement">=</span><span class="Identifier">%USERNAME%</span> <span class="Statement">call</span><span class="Statement"> :read_no_history</span> user <span class="Identifier">%user%</span> <span class="Constant">"Username"</span> <span class="Identifier">rem</span><span class="Comment"> CONFIGURE: Set your preferred realm here. By default, the script</span> <span class="Identifier">rem</span><span class="Comment"> assumes two-stage authentication using a PIN and RSA SecurID.</span> <span class="Identifier">set</span><span class="Identifier"> realm</span><span class="Statement">=</span><span class="Constant">"SecurID(Network Connect)"</span> <span class="Statement">call</span><span class="Statement"> :read_no_history</span> realm <span class="Identifier">%realm%</span> <span class="Constant">"Realm"</span> <span class="Identifier">REM</span><span class="Comment"> </span><span class="Todo">TODO</span><span class="Comment">: Hide password input</span> <span class="Identifier">set</span><span class="Identifier"> password</span><span class="Statement">=</span><span class="Constant">""</span> <span class="Statement">call</span><span class="Statement"> :read_no_history</span> password <span class="Identifier">%password%</span> <span class="Constant">"Enter PIN + token value for user </span><span class="Identifier">%user%</span><span class="Constant">:"</span> <span class="Statement">if</span><span class="Statement"> </span>x<span class="Identifier">%password%</span><span class="Statement">==</span>x ( <span class="Identifier">echo</span><span class="Constant"> ERROR: No password specified</span> <span class="Statement">goto</span><span class="Statement"> :end</span> ) <span class="Identifier">cls</span> <span class="Identifier">echo</span><span class="Constant"> Launching Juniper Network Connect client in</span> <span class="Identifier">echo</span><span class="Constant"> </span><span class="Identifier">%NCCLIENTDIR%</span><span class="Constant">...</span> <span class="Constant">"</span><span class="Identifier">%NCCLIENTDIR%</span><span class="Constant">\nclauncher.exe"</span> -url <span class="Identifier">%url%</span> -u <span class="Identifier">%user%</span> -p <span class="Identifier">%password%</span> -r <span class="Identifier">%realm%</span> <span class="Statement">goto</span><span class="Statement"> :end</span> <span class="Identifier">REM</span><span class="Comment"> --------------------------------------------------------</span> <span class="Statement">:find_juniper_client</span> <span class="Identifier">setlocal</span> <span class="Identifier">set</span><span class="Identifier"> CLIENT</span><span class="Statement">=</span> <span class="Identifier">rem</span><span class="Comment"> search registry first</span> <span class="Statement">for</span> <span class="Special">/f</span> <span class="Constant">"tokens=</span><span class="Constant">1</span><span class="Constant">* delims= "</span> <span class="Special">%%</span>A in (<span class="PreProc">'reg query </span><span class="Constant">"HKLM\SOFTWARE\Juniper Networks"</span><span class="PreProc"> </span><span class="Constant">2</span><span class="PreProc">^>nul'</span>) do <span class="Identifier">set</span><span class="Identifier"> LATESTVERSION</span><span class="Statement">=</span><span class="Constant">"</span><span class="Special">%%</span><span class="Constant">A"</span> <span class="Statement">if</span><span class="Statement"> </span>x<span class="Identifier">%LATESTVERSION%</span><span class="Statement">==</span>x<span class="Constant">""</span> <span class="Statement">goto</span><span class="Statement"> :eof</span> <span class="Statement">for</span> <span class="Special">/f</span> <span class="Constant">"tokens=</span><span class="Constant">2</span><span class="Constant">* delims= "</span> <span class="Special">%%</span>A in (<span class="PreProc">'reg query </span><span class="Identifier">%LATESTVERSION%</span><span class="PreProc"> /v InstallPath </span><span class="Constant">2</span><span class="PreProc">^>nul ^| </span><span class="Identifier">findstr</span><span class="PreProc"> InstallPath'</span>) do <span class="Identifier">set</span><span class="Identifier"> CLIENT</span><span class="Statement">=</span><span class="Special">%%</span>B <span class="Identifier">rem</span><span class="Comment"> if nothing found, check filesystem</span> <span class="Statement">if</span><span class="Statement"> </span><span class="Constant">"x</span><span class="Identifier">%CLIENT%</span><span class="Constant">"</span><span class="Statement">==</span><span class="Constant">"x"</span> <span class="Statement">for</span> <span class="Special">/d</span> <span class="Special">%%</span>A in (<span class="Constant">"%ProgramFiles(x86)%\Juniper Networks\Network Connect*"</span>) do <span class="Identifier">set</span><span class="Identifier"> CLIENT</span><span class="Statement">=</span><span class="Special">%%</span>A <span class="Statement">if</span><span class="Statement"> </span><span class="Constant">"x</span><span class="Identifier">%CLIENT%</span><span class="Constant">"</span><span class="Statement">==</span><span class="Constant">"x"</span> <span class="Statement">for</span> <span class="Special">/d</span> <span class="Special">%%</span>A in (<span class="Constant">"</span><span class="Identifier">%ProgramFiles%</span><span class="Constant">\Juniper Networks\Network Connect*"</span>) do <span class="Identifier">set</span><span class="Identifier"> CLIENT</span><span class="Statement">=</span><span class="Special">%%</span>A <span class="Identifier">endlocal</span><span class="Statement"> & </span><span class="Identifier">set</span> <span class="Constant">"%~</span><span class="Constant">1</span><span class="Constant">=</span><span class="Identifier">%CLIENT%</span><span class="Constant">"</span> <span class="Statement">goto</span><span class="Statement"> :eof</span> <span class="Identifier">REM</span><span class="Comment"> --------------------------------------------------------</span> <span class="Identifier">REM</span><span class="Comment"> read_no_history promptvar default promptmessage</span> <span class="Statement">:read_no_history</span> <span class="Identifier">setlocal</span> <span class="Identifier">set</span><span class="Identifier"> msg</span><span class="Statement">=</span>%~<span class="Constant">3</span> <span class="Statement">if</span><span class="Statement"> not </span><span class="Constant">"x%~</span><span class="Constant">2</span><span class="Constant">"</span><span class="Statement">==</span><span class="Constant">"x"</span> ( <span class="Identifier">set</span><span class="Identifier"> msg</span><span class="Statement">=</span><span class="Constant">"%~</span><span class="Constant">3</span><span class="Constant"> (default: %~</span><span class="Constant">2</span><span class="Constant">): "</span> ) <span class="Identifier">set</span> <span class="Special">/P</span><span class="Identifier"> RNH_TEMP</span><span class="Statement">=</span><span class="Identifier">%msg%</span> <nul <span class="Identifier">set</span><span class="Identifier"> RNH_TEMP</span><span class="Statement">=</span> <span class="Identifier">REM</span><span class="Comment"> call external script to avoid adding to our own command history</span> <span class="Identifier">set</span><span class="Identifier"> RNH_CMDFILE</span><span class="Statement">=</span><span class="Identifier">%TEMP%</span>\temp<span class="Special">$$</span>$.<span class="Identifier">cmd</span> ( <span class="Identifier">echo</span><span class="Constant"> @echo off</span> <span class="Identifier">echo</span><span class="Constant"> set var_=</span><span class="Identifier">%2</span> <span class="Identifier">echo</span><span class="Constant"> set /p var_=</span> <span class="Identifier">echo</span><span class="Constant"> echo </span><span class="Special">%%</span><span class="Constant">var_</span><span class="Special">%%</span> )> <span class="Constant">"</span><span class="Identifier">%RNH_CMDFILE%</span><span class="Constant">"</span> <span class="Statement">for</span> <span class="Special">/f</span> <span class="Constant">"delims=,"</span> <span class="Special">%%</span>A in (<span class="PreProc">'</span><span class="Identifier">%RNH_CMDFILE%</span><span class="PreProc">'</span>) do <span class="Identifier">set</span><span class="Identifier"> RNH_TEMP</span><span class="Statement">=</span><span class="Special">%%</span>A <span class="Identifier">del</span> <span class="Identifier">%RNH_CMDFILE%</span> <span class="Identifier">endlocal</span><span class="Statement"> & </span><span class="Statement">if</span><span class="Statement"> not </span>x<span class="Identifier">%RNH_TEMP%</span><span class="Statement">==</span>x <span class="Identifier">set</span> <span class="Constant">"%~</span><span class="Constant">1</span><span class="Constant">=</span><span class="Identifier">%RNH_TEMP%</span><span class="Constant">"</span> <span class="Statement">goto</span><span class="Statement"> :eof</span> <span class="Identifier">REM</span><span class="Comment"> --------------------------------------------------------</span> <span class="Statement">:end</span> <span class="Identifier">endlocal</span> </pre> The above script is meant to be used along with the Windows version of the Network Connect client. For the Linux client, Paul D. Smith provides an excellent script and great instructions at http://mad-scientist.us/juniper.html. See below for the direct download link for the script. PS: The code is now available from github as well, see https://github.com/clausb/nclauncher. PS/2: Paul D. Smith's instructions are unavailable as of November 2015; the Wayback archive still has a copy at http://web.archive.org/web/20150908095435/http://mad-scientist.us/juniper.html. <!-- * http://www.juniper.net/techpubs/software/ive/guides/howtos/How_To_NC_Config.pdf * http://www.juniper.net/support/products/pulse/ * http://www-pc.uni-regensburg.de/systemsw/TOOLS/vpnclient.htm * http://www.juniper.net/techpubs/en_US/sa7.1/topics/reference/general/secure-access-csc-network-connect-linux.html * http://www.juniper.net/techpubs/software/pulse/guides/j-pulse-2.0R1-migrationguide.pdf --> --- %STOPINCLUDE% %COMMENT{type="below" nonotify="on"}% ---
to top
End of topic
Skip to action links
|
Back to top
Edit
|
Attach image or document
|
Printable version
|
Raw text
|
Refresh
|
More topic actions
Revisions: | r1.6 |
>
|
r1.5
|
>
|
r1.4
|
Total page history
|
Backlinks
You are here:
Blog
>
DefinePrivatePublic20110820JuniperNetworkConnect
r1.6 - 25 Nov 2015 - 22:03 -
ClausBrod
to top
Blog
This site
2017
:
12
-
11
-
10
2016
:
10
-
7
-
3
2015
:
11
-
10
-
9
-
4
-
1
2014
:
5
2013
:
9
-
8
-
7
-
6
-
5
2012
:
2
-
10
2011
:
1
-
8
-
9
-
10
-
12
2010
:
11
-
10
-
9
-
4
2009
:
11
-
9
-
8
-
7
-
6
-
5
-
4
-
3
2008
:
5
-
4
-
3
-
1
2007:
12
-
8
-
7
-
6
-
5
-
4
-
3
-
1
2006:
4
-
3
-
2
-
1
2005:
12
-
6
-
5
-
4
2004:
12
-
11
-
10
C++
CoCreate Modeling
COM & .NET
Java
Mac
Lisp
OpenSource
Scripting
Windows
Stuff
Changes
Index
Search
Maintenance
Impressum
Datenschutzerklärung
Home
Webs
Atari
Blog
Claus
CoCreateModeling
Klassentreffen
Main
Sandbox
Sommelier
TWiki
Xplm
Jump:
Copyright © 1999-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback