Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

HELP: Script to gather IP Address from .RDP then compile to .exe for VNC

authentication

  • Please log in to reply
69 replies to this topic

#13 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 07 June 2009 - 06:18 PM

Thanks, though I would still like everyone to get a look at the CSV file, to confirm that what you've been suggesting is possible.

Supposing it's something like;

255.255.255.255, Panarchy
124.323.125.235, SandMan
...

Could you please give me an example of how the code to input the data into the .cpp file, then compile it with the name look?

Thanks in advance,

Panarchy
  • 0

#14 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 07 June 2009 - 06:59 PM

Same thing. You put a token in the template CPP file that doesn't appear anywhere else, then you do a string replace.
  • 0

#15 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 08 June 2009 - 03:25 PM

Can I do a per-line replacement?

As I'm thinking that would be better... I can put the IP Address on a line of it's own.

Also, could I please have an example of how the end-code should look?

Thanks in advance,

Panarchy
  • 0

#16 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 08 June 2009 - 03:51 PM

No need to. Prepare to be amazed by the power of Perl.

#!/usr/bin/env perl

use strict;

my (@iplist,@template,$currip,@outln) = ((),(),'','')

#fill iplist with ip's here

#open template file
open(CPPTEMPLATE,"<cpptemplate.cpp") or die "Failed to open template file.";

#load entire file into array
@template = <CPPTEMPLATE>;

#for each ip address in the list....
foreach(@iplist)
{
	#get the current ip
	$currip = $_;
	
	#open the output file
	open(CPPOUT,">$currip.cpp") or die "Failed to open $currip for writing.";
	#for every line in the template file...
	foreach(@template)
	{
		#replace all occurrences of __PUTIPHERE__ with the current ip
		$outln =~ /__PUTIPHERE__/$currip/g;
		#write it out to the output file
		print CPPOUT $outln
	}
	#close the output file
	close(CPPOUT);
}

#close template file
close(CPPTEMPLATE);

#exit
0;

  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#17 ikonia

ikonia

    CC Newcomer

  • Just Joined
  • PipPip
  • 22 posts

Posted 09 June 2009 - 02:36 AM

now that's some tidy perl, slick
  • 0

#18 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 09 June 2009 - 05:40 AM

*insert applause emoticon here*

Thanks dargueta. To mix good news with good news, I received the .csv file today!

:D

Two quick questions;
  • How do I concatenate the .csv file into the Perl script? You did declare @iplist, however I don't understand how you'd like it sorted. Also, the names...
  • The compiler options/commands, where do they fit in?
    [B]cl[/B] /[B]clr[/B] "super.cpp"
    [B]link[/B] super-resouce.res main.obj /[B]out[/B]:"%name%".exe
Your code is beautiful. Please use your talent to add the missing capabilities listed above.

Thanks once again,

Panarchy
  • 0

#19 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 09 June 2009 - 04:00 PM

Post the CSV so I can see what the fields are like, then I'll write it up tonight. Should take me all of five minutes, I think.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#20 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 09 June 2009 - 04:42 PM

Excellent, I'll be looking forward to the end product.

Book1.csv

Also, unsure of why I am yet to post it, but here are the project files for the VNC Authentication;

Code::Blocks project: VNC.zip

Visual Studio 2008 project: VNC.zip

Thanks for all your help, will be looking forward to tonight [in your timezone!]

Panarchy

Edited by Panarchy, 09 June 2009 - 05:42 PM.

  • 0

#21 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 09 June 2009 - 08:04 PM

Probably not going to happen tonight, something came up. I'll see what I can do.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#22 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 09 June 2009 - 11:13 PM

Thanks, appreciate it.
  • 0

#23 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 11 June 2009 - 03:51 PM

Please get back to this first chance you get.

Thanks in advance,

Panarchy
  • 0

#24 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 16 June 2009 - 06:09 PM

Haven't tested this, but I think it'll work.

#!/usr/bin/env perl

use strict;

my (@iplist,$template,$currip) = ((),'','');

#open ip list file
open(IPFILE,"<iplist.csv") or die "Failed to open IP list file.";
#read all lines into array
my @ipfile,$i = ((),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.
	$iplist[$i] =~ split(/^*,(*)$/,$_);
	++$i;
}
#close ip list file
close(IPFILE);

#open template file
open(CPPTEMPLATE,"<cpptemplate.cpp") or die "Failed to open template file.";

#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 = <CPPTEMPLATE>;

#reset $/ to avoid problems.
$/ = "\n";

#for each ip address in the list...
foreach(@iplist)
{
	#get the current ip
	$currip = $_;
	#open the output file
	open(CPPOUT,">$currip.cpp") or die "Failed to open $currip.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);
}

#close template file
close(CPPTEMPLATE);

#exit
1;

  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'






Also tagged with one or more of these keywords: authentication

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download