Lobus has asked for the wisdom of the Perl Monks concerning the following question:
#!Perl use 5.010; use strict; use warnings; # Clears the screen system("cls"); say ""; say " *---------------------------------------------*" +; say " *Welcome to Team Starcraft VNC rollout program*" +; say " *---------------------------------------------*" +; say ""; say ""; say ""; say ""; # Defines variables my $ipInput = 0; my $userName = 0; my $passWord = 0; my $ip = 0; my $choice = 0; my $fileName = 0; my $resultOutput = "Results.txt"; # Defines the IP arrays my @ip = (); my @pingFail = (); my @badUnPass = (); my @vncSuccess = (); # User picks what version to run say "How would you like input IP addresses?\n"; say "(Option #1) Enter every IP Ex: xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx, +etc...\n"; say "(Option #2) Enter the name of a file that contains a list of IP a +ddresses\n"; say "Please select 1 or 2\n"; chomp($choice = <STDIN>); #Options if ($choice == 1) { # User input say "Please enter the username:\n"; chomp($userName = <STDIN>); say ""; say "Please enter the password:\n"; chomp($passWord = <STDIN>); say ""; say "Please enter the ip addresses of the machines you would like to i +nstall VNC on\n"; say "Ex: xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx, etc...\n"; chomp($ipInput = <STDIN>); # Sets delimeter for array input @ip = split(',',$ipInput); @pingFail = split(',',$ip); @badUnPass = split(',',$ip); @vncSuccess = split(',',$ip); # Clears the screen system("cls"); # A loop that will perform the operation on each machine, from wich an + ip was given foreach $ip(@ip) { my $Result = system("ping $ip -w 300"); if ($Result == 0) { # Initiate the connection $Result = system("net use \\\\$ip\\IPC\$ /user:$userName $passWord"); if ($Result == 0) { # Copies the program files `xcopy "C:\\Program Files\\UltraVNC\\*.*" "\\\\$ip\\C\$\\Program Files +\\UltraVNC\\*.*" /r/i/c/h/k/e/Y`; # Dumps the registry `regedit /e "\\\\$ip\\C\$\\vncdmp.txt" "HKEY_LOCAL_MACHINE\\Software\\ +ORL"`; # Puts registry entries on remote machine `psexec \\\\$ip -s -i -d %windir%\\regedit /s C:\\vncdmp.txt`; # Installs the program as a service `psexec \\\\$ip -s -i -d "C:\\Program Files\\UltraVNC\\winvnc.exe" -in +stall`; # Starts the VNC server `psexec \\\\$ip -s -i -d net start VNC Server`; #This puts the IP address that deployed propery into an array push(@vncSuccess,$ip); say ""; say " *---------------------------------------------*" +; say " VNC deployed"; say " *---------------------------------------------*" +; } else { #This puts the IP address that could not be propery connected to into +an array push(@badUnPass,$ip); say ""; say " *---------------------------------------------*" +; say " Bad username or password"; say " *---------------------------------------------*" +; } } else { #This puts the IP addresses that could not be reached via ping into an + array push(@pingFail,$ip); say ""; say " *---------------------------------------------*" +; say " Unable to reach:"; say " $ip"; say " *---------------------------------------------*" +; } # Ends foreach $ip(@ip) { } # Ends if ($choice == 1) { } elsif ($choice == 2) { # User input say "Please enter the username:\n"; chomp($userName = <STDIN>); say ""; say "Please enter the password:\n"; chomp($passWord = <STDIN>); say ""; say "Please enter the name of a file that contains a list of IP addres +ses.\n"; say "The syntax is xxxx.xxx"; chomp($fileName=<STDIN>); open(DAT, $fileName) || die("Could not find file!"); $ipInput=<DAT>; close(DAT); # Sets delimeter for array input @ip = split(',',$ipInput); @pingFail = split(',',$ip); @badUnPass = split(',',$ip); @vncSuccess = split(',',$ip); # Clears the screen system("cls"); # A loop that will perform the operation on each machine, from wich an + ip was given foreach $ip(@ip) { my $Result = system("ping $ip -w 300"); if ($Result == 0) { # Initiate the connection $Result = system("net use \\\\$ip\\IPC\$ /user:$userName $passWord"); if ($Result == 0) { # Copies the program files `xcopy "C:\\Program Files\\UltraVNC\\*.*" "\\\\$ip\\C\$\\Program Files +\\UltraVNC\\*.*" /r/i/c/h/k/e/Y`; # Dumps the registry `regedit /e "\\\\$ip\\C\$\\vncdmp.txt" "HKEY_LOCAL_MACHINE\\Software\\ +ORL"`; # Puts registry entries on remote machine `psexec \\\\$ip -s -i -d %windir%\\regedit /s C:\\vncdmp.txt`; # Installs the program as a service `psexec \\\\$ip -s -i -d "C:\\Program Files\\UltraVNC\\winvnc.exe" -in +stall`; # Starts the VNC server `psexec \\\\$ip -s -i -d net start VNC Server`; #This puts the IP address that deployed propery into an array push(@vncSuccess,$ip); say ""; say " *---------------------------------------------*" +; say " VNC deployed"; say " *---------------------------------------------*" +; } else { #This puts the IP address that could not be propery connected to into +an array push(@badUnPass,$ip); say ""; say " *---------------------------------------------*" +; say " Bad username or password"; say " *---------------------------------------------*" +; } } else { #This puts the IP addresses that could not be reached via ping into an + array push(@pingFail,$ip); say ""; say " *---------------------------------------------*" +; say " Unable to reach:"; say " $ip"; say " *---------------------------------------------*" +; } # Ends foreach $ip(@ip) { } } else { system("cls"); say ""; say " *---------------------------------------------*" +; say " Bad input"; say " Please only select 1 or 2"; say " *---------------------------------------------*" +; system("pause"); system("perl VNC-push.pl"); } open(DAT,">$resultOutput") || die("Cannot Open File"); print DAT "VNC successfully deployed on the following machines:\n"; print DAT "\n"; close(DAT); shift(@vncSuccess); foreach $ip(@vncSuccess) { open(DAT,">>$resultOutput") || die("Cannot Open File"); print DAT "$ip\n"; print DAT "\n"; close(DAT); } open(DAT,">>$resultOutput") || die("Cannot Open File"); print DAT "Could not reach the following addresses:\n"; print DAT "\n"; close(DAT); shift(@pingFail); foreach $ip(@pingFail) { open(DAT,">>$resultOutput") || die("Cannot Open File"); print DAT "$ip\n"; print DAT "\n"; close(DAT); } open(DAT,">>$resultOutput") || die("Cannot Open File"); print DAT "Bad username or password on the following machines:\n"; print DAT "\n"; close(DAT); shift(@badUnPass); foreach $ip(@badUnPass) { open(DAT,">>$resultOutput") || die("Cannot Open File"); print DAT "$ip\n"; print DAT "\n"; close(DAT); } # By Kevin Davies.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net Use issues
by missingthepoint (Friar) on Feb 16, 2009 at 09:44 UTC | |
by Lobus (Initiate) on Feb 16, 2009 at 18:09 UTC | |
|
Re: Net Use issues
by Anonymous Monk on Feb 16, 2009 at 07:50 UTC | |
by Lobus (Initiate) on Feb 16, 2009 at 16:21 UTC | |
by Anonymous Monk on Feb 17, 2009 at 00:04 UTC | |
|
Re: Net Use issues
by jasonk (Parson) on Feb 16, 2009 at 17:25 UTC | |
by Lobus (Initiate) on Feb 18, 2009 at 02:42 UTC | |
by missingthepoint (Friar) on Feb 20, 2009 at 09:54 UTC |