Oh!!!
Thanks, I'll give it a go.
Hopefully this line doesn't need correcting;
Code:#open template file open(CPPTEMPLATE,"<VNC.cpp>") or die "Failed to open template file.";
Change this:
To this:Code:open(CPPTEMPLATE,"<VNC.cpp>") or die "Failed to open template file.";
...and change this:Code:open(CPPTEMPLATE,"<VNC.cpp") or die "Failed to open template file.";
to this:Code:$template =~ /__PUTIPHERE__/$currip/g;
Code:$template =~ s/__PUTIPHERE__/$currip/g;
sudo rm -rf /
Thanks.
The script now runs successfully... however...
It doesn't work. This may make things a little clearer;
Please complete this script.
Thanks in advance,
Panarchy
EDIT: Althought the screenshot doesn't show it, I ran the script in between. It didn't say 'ran successfully' or anything like that, but didn't give errors.
I'm confused.
sudo rm -rf /
Code:#!/usr/bin/env perl use strict; use warnings; use POSIX; #declare whitespace-trimming function defined later sub trim($); my (@iplist,@hostlist,$template,$hostname,$currip,$currhost) = ((),(),'','','',''); #open ip list file open(IPFILE,"<iplist.csv") or die "Failed to open IP list file."; #read all lines into array my (@ipfile,$i,$total) = ((),0,0); @ipfile = <IPFILE>; #for each line in the ip file... foreach(@ipfile) { #strip leading and trailing spaces off the line chomp($_); #use regular expressions to pull the #ip address from the line. I have to #check to see if the regex will do #what it's supposed to. ($hostlist[$i],$iplist[$i]) =~ split(/,/); #remove leading and trailing whitespace $hostlist[$i] = trim($hostlist[$i]); $iplist[$i] = trim($iplist[$i]); ++$i; ++$total; } #close ip list file close(IPFILE); #open template file open(CPPTEMPLATE,"<VNC.cpp") or die "Failed to open template file."; #for each ip address in the list... for($i = 0; $i < $total; ++$i) { #load entire file into single string... #undefine end-of-record variable, which is \n by default. this will result #in the file being divided up into an array of lines instead of one single #string like we want. undef $/; #read the file into $template. $template = <VNC.cpp>; #reset $/ to avoid problems. $/ = "\n"; #get the current ip & host $currip = $iplist[$i]; $currhost = $hostlist[$i]; #open the output file open(CPPOUT,">$currhost.cpp") or die "Failed to open $currhost.cpp for writing."; #replace all instances of __PUTIPHERE__ in the template file with the #current ip address. $template =~ /__PUTIPHERE__/$currip/g; #print the result to the output file. print CPPOUT $template; #close the output file close(CPPOUT); #compile `cl /clr $currhost.cpp`; `link super-resource.res main.obj /out:$currhost.exe`; #rewind to beginning of template file to read again seek(CPPTEMPLATE,0,SEEK_SET); } #close template file close(CPPTEMPLATE); #exit 1; #### sub trim($) { my $str = shift; $str =~ s/^\s+//; $str =~ s/\s+$//; return $str; }
Last edited by dargueta; 07-29-2009 at 10:25 PM.
sudo rm -rf /
Thanks a heap!
Looks pretty much complete now!
Hate to disappoint you, but I'm getting this error;
Please fix!
I feel that it's very close to completion!
Thanks,
Panarchy
Well, for starters you didn't make the fix I mentioned earlier with prefixing 's' to the regex. And it looks like you're running a more recent version of Perl than I am. My fail.
Code:#!/usr/bin/env perl use strict; use warnings; use POSIX; #declare whitespace-trimming function defined later sub trim($); my (@iplist,@hostlist,$template,$hostname,$currip,$currhost) = ((),(),'','','',''); #open ip list file open(IPFILE,"<iplist.csv") or die "Failed to open IP list file."; #read all lines into array my (@ipfile,$i,$total) = ((),0,0); @ipfile = <IPFILE>; #for each line in the ip file... foreach(@ipfile) { #strip leading and trailing spaces off the line chomp($_); #use regular expressions to pull the #ip address from the line. I have to #check to see if the regex will do #what it's supposed to. ($hostlist[$i],$iplist[$i]) =~ split(/,/,$_); #remove leading and trailing whitespace $hostlist[$i] = trim($hostlist[$i]); $iplist[$i] = trim($iplist[$i]); ++$i; ++$total; } #close ip list file close(IPFILE); #open template file open(CPPTEMPLATE,"<VNC.cpp") or die "Failed to open template file."; #for each ip address in the list... for($i = 0; $i < $total; ++$i) { #load entire file into single string... #undefine end-of-record variable, which is \n by default. this will result #in the file being divided up into an array of lines instead of one single #string like we want. undef $/; #read the file into $template. $template = <VNC.cpp>; #reset $/ to avoid problems. $/ = "\n"; #get the current ip & host $currip = $iplist[$i]; $currhost = $hostlist[$i]; #open the output file open(CPPOUT,">$currhost.cpp") or die "Failed to open $currhost.cpp for writing."; #replace all instances of __PUTIPHERE__ in the template file with the #current ip address. $template =~ s/__PUTIPHERE__/$currip/g; #print the result to the output file. print CPPOUT $template; #close the output file close(CPPOUT); #compile `cl /clr $currhost.cpp`; `link super-resource.res main.obj /out:$currhost.exe`; #rewind to beginning of template file to read again seek(CPPTEMPLATE,0,SEEK_SET); } #close template file close(CPPTEMPLATE); #exit 1; #### sub trim($) { my $str = shift; $str =~ s/^\s+//; $str =~ s/\s+$//; return $str; }
sudo rm -rf /
Hi
Thanks, from the looks of things, it'll work now.
I'll try tomorrow, as I don't have the script, scripting engine, csv file or Visual Studio with me at the moment.
Thanks once again,
Panarchy
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks