Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
The code:
#!/usr/bin/perl -w # written by Daniel Schrock # # ver. 0.1 - 03/17/04 - initial testing and dev. # ver. 0.2 - 04/23/04 - First working version # # Requirements: # -ActiveState Perl 5.8.2 or higher # -Win32::TieRegistry module (use ppm or CPAN) # -Win32::Shortcut (use ppm or CPAN) use strict 'vars'; my $Registry; use Win32::TieRegistry( TiedRef => \$Registry, Delimiter=>"/", qw( REG +_SZ REG_EXPAND_SZ REG_DWORD REG_BINARY REG_MULTI_SZ KEY_READ KEY_WRIT +E KEY_ALL_ACCESS ),); use Win32::Shortcut; #my $print_output="notTRUE"; my $print_output="TRUE"; my $ignore='^\s*#|^\s*\n\r*'; my $base_dir= "c:/NoInstall"; my $user; my $netuser= "admin"; my $sshuser= $ARGV[0]||""; my $tmpuser; my $server_list= "$base_dir/servers.txt"; my $folder; my $protocol; my $protover; my $version; my $session_name; my $server_name; my $app="putty.exe"; my $appdir="$base_dir/$app"; my $dest_dir="$base_dir/putty-sessions"; my $LINK; my $RegPath= "CUser/Software/SimonTatham/PuTTY/Sessions/"; my $hexport; my $protoport; my $compr; my $protocompr; &check_putty_exe; &check_putty_session_dir; open(SERVER_LIST,$server_list)||die "Can't open $server_list: $!\n"; while (<SERVER_LIST>) { next if /$ignore/ ; chop; ( $folder, $server_name, $session_name, $protocol)= split (":"); ($hexport,$version,$compr)=create_port($protocol); $user=create_user($folder); &create_session($server_name, $session_name, $protocol, $user); &create_link($folder, $server_name, $session_name); } close(SERVER_LIST); exit; sub check_putty_exe { if (! -f "$appdir" ) { print "$appdir not found!\n\n Unable to continue!\n\n Please mov +e/copy $app into $base_dir and rerun this script\n"; exit 1; }else{ print "Excellent! Found $app in $base_dir\n"; } } sub check_putty_session_dir { if (! -d "$dest_dir" ) { print "$dest_dir not found.\nCreating $dest_dir\n"; mkdir $dest_dir || die "Error! Can not create $dest_dir"; }else{ print "$dest_dir found.\nCreating a backup\n"; if ( -d "$dest_dir.bak" ) { print "Found previous backup.\nPlease remove and rerun the + script.\n"; exit 1; } rename $dest_dir, $dest_dir.'.bak' || die "Couldn't backup $de +st_dir\n"; print "Backup created.\n\( $dest_dir.bak \)\nCreating new sess +ion directory\n\n"; mkdir $dest_dir || die "Error! Can not create $dest_dir"; print "New session directory created.\n\( $dest_dir \)\n"; } } sub create_port { if ( $protocol eq "telnet" ) { $protoport= "0x00017"; $protover= "0x00003"; $protocompr= "0x00000"; }elsif ( $protocol eq "ssh2" ) { $protoport= "0x00016"; $protover= "0x00003"; $protocompr= "0x00001"; }elsif ( $protocol eq "ssh1" ) { $protoport= "0x00016"; $protover= "0x00002"; $protocompr= "0x00000"; } return ($protoport, $protover, $protocompr); } sub create_user { if ( $folder eq "network" || $folder eq "frame" || $folder eq "s2s +-vpn" ) { $tmpuser= $netuser; }else{ $tmpuser= $sshuser; } return($tmpuser); } sub create_link { if (! -d "$dest_dir/$folder" ) { mkdir "$dest_dir/$folder" || die "Error! Can not create $dest_ +dir/$folder"; } $LINK=new Win32::Shortcut(); $LINK->{'Path'}="$appdir"; $LINK->{'Arguments'}="-load $session_name"; $LINK->{'WorkingDirectory'}="$base_dir"; $LINK->{'Description'}="$server_name"; $LINK->{'ShowCmd'}=SW_SHOWNORMAL; $LINK->{'IconLocation'}="$appdir"; $LINK->{'IconNumber'}=0; $LINK->Save("$dest_dir/$folder/$session_name.lnk"); $LINK->Close(); print "$dest_dir/$folder/$session_name.lnk created.\n" } sub create_session { $Registry->{"$RegPath"}= { "$session_name/" => { "/HostName" => "$server_name", "/Protocol" => "$protocol", "/PortNumber" => ["$hexport", REG_DWORD ], "/PingIntervalSecs" => [ "0x0001", REG_DWORD ], "/TCPNoDelay" => [ "0x0000", REG_DWORD ], "/UserName" => "$user", "/Compression" => [ "$compr", REG_DWORD ], "/Cipher" => "blowfish,aes,3des,WARN,des", "/SshProt" => [ "$version", REG_DWORD ], "/LinuxFunctionKeys" => [ "0x0002", REG_DWORD ], "/BLinkCur" => [ "0x0001", REG_DWORD ], "/ScrollbackLines" => [ "0x07d0", REG_DWORD ], }, } || die "Can't create $RegPath/$session_name: $^E\n"; }
The Config File:
###CONSOLES consoles:server1-console.example.com:server1-console:telnet consoles:server2-console.example.com:server2-console:telnet consoles:server3-console.example.com:server3-console:telnet consoles:server4-console.example.com:server4-console:telnet consoles:router1-console.example.com:router1-console:telnet consoles:router2-console.example.com:router2-console:telnet ####CONSOLES ###DMZ dmz:ns01.example.com:ns01:ssh2 dmz:ns02.example.com:ns02:ssh2 dmz:web01.example.com:web01:ssh2 dmz:web02.example.com:web02:ssh2 ####DMZ ###FRAME frame:framerelay1.example.com:framerelay1:telnet frame:framerelay2.example.com:framerelay2:telnet ####FRAME ###INSIDE inside:server1.example.com:server1:ssh2 inside:server2.example.com:server2:ssh2 inside:server3.example.com:server3:ssh2 inside:server4.example.com:server4:ssh2 ####INSIDE ###NETWORK network:switch1.example.com:switch1:telnet network:switch2.example.com:switch2:telnet network:switch3.example.com:switch3:telnet network:router1.example.com:router1:ssh2 network:router2.example.com:router2:ssh2 network:bigip01.example.com:bigip01:ssh2 network:bigip02.example.com:bigip02:ssh2 network:pix525.example.com:pix525:ssh1 network:console-server.example.com:console-server:ssh1 ####NETWORK ###VPN s2s-vpn:pix506.example.com:pix506:ssh1 ####VPN ###ROUTE SERVERS route-servers:route-server.ip.att.net:route-server.ip.att.net:telnet route-servers:route-server.cerf.net:route-server.cerf.net:telnet route-servers:route-server.colt.net:route-server.colt.net:telnet route-servers:route-server.exodus.net:route-server.exodus.net:telnet route-servers:route-server.gblx.net:route-server.gblx.net:telnet route-servers:route-views.oregon-ix.net:route-views.oregon-ix.net:teln +et ####ROUTE SERVERS ###PERSONAL personal:192.168.0.1:pix:ssh1 personal:192.168.0.2:2924:telnet personal:192.168.0.200:server1:ssh2 personal:192.168.0.254:server2:ssh2 personal:192.168.0.253:server3:ssh2 ####PERSONAL
After running, just create a new toolbar that points to the putty-sessions folder.

In reply to Putty Session Generator by d_jabsd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found