#!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 addresses\n"; say "Please select 1 or 2\n"; chomp($choice = ); #Options if ($choice == 1) { # User input say "Please enter the username:\n"; chomp($userName = ); say ""; say "Please enter the password:\n"; chomp($passWord = ); say ""; say "Please enter the ip addresses of the machines you would like to install VNC on\n"; say "Ex: xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx, etc...\n"; chomp($ipInput = ); # 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" -install`; # 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 = ); say ""; say "Please enter the password:\n"; chomp($passWord = ); say ""; say "Please enter the name of a file that contains a list of IP addresses.\n"; say "The syntax is xxxx.xxx"; chomp($fileName=); open(DAT, $fileName) || die("Could not find file!"); $ipInput=; 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" -install`; # 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.