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

#25 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 17 June 2009 - 06:35 PM

Thanks for the code.

Unfortunately, it doesn't work :(

Posted Image

#!/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,"<VNC.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 = VNC.cpp;

#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);

#should the above text 'CPPTEMPLATE' be replaced with VNC.cpp?

#exit
1;
Please help me get it to work!

Thanks in advance,

Panarchy
  • 0

#26 dargueta

dargueta

    I chown trolls.

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

Posted 17 June 2009 - 08:26 PM

That would be because I'm an idiot...

#!/usr/bin/env perl

use strict;

my (@iplist,$template,$hostname,$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.
	($hostname,$iplist[$i]) =~ split(/,/);
	chomp($iplist[$i]);
	++$i;
}
#close ip list file
close(IPFILE);

#open template file
open(CPPTEMPLATE,"<VNC.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 = VNC.cpp;

#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);

#should the above text 'CPPTEMPLATE' be replaced with VNC.cpp?

#exit
1;

  • 0

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


#27 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 18 June 2009 - 12:12 AM

Thanks, however there are still some missing features.

To be clearer, I have listed them in 4 steps;


Step 1. Process IP Address from CSV
Step 2. Process Name from CSV
Step 3. Input IP Address into VNC.cpp
Step 4. Compile with Name



It seems that Step 4 has been left out... please include it.

To confirm, Step 4 should correspond the following;
[B]cl[/B] /clr "super.cpp"
[B]link[/B] super-resource.res main.obj /[B]out[/B]:"%name%".exe

We're almost there... Please help me complete this!

Thanks in advance,

Panarchy
  • 0

#28 dargueta

dargueta

    I chown trolls.

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

Posted 18 June 2009 - 11:15 AM

Dude, I'd love to help, but I have a full-time job. I think the rest is rather straight-forward enough for you to figure out with the Perl tutorials below:

Starting Perl (Good but out of date)
PerlTutorial.org (Great for people who already know how to program)
  • 0

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


#29 ikonia

ikonia

    CC Newcomer

  • Just Joined
  • PipPip
  • 22 posts

Posted 18 June 2009 - 10:12 PM

you just need to call the compiler with the correct arguments then start the loop again
  • 0

#30 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 19 June 2009 - 05:32 PM

Dargueta: As do I!

Well, I'll read through the tutorial, and come back here if I need more help.

Once I've worked it out, I'll post the completed code here.

Thanks for your help Dargueta,

Panarchy
  • 0

#31 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 07 July 2009 - 12:52 AM

Unfortunately, I haven't had the time to finish the script.

If you Dargueta, get the chance, or if anyone else does, could the script please get finished?

Thanks in advance,

Panarchy
  • 0

#32 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 25 July 2009 - 01:47 AM

*bump

BTW: Interesting new button icons/backgrounds here! Nice work ;)
  • 0

#33 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 25 July 2009 - 03:04 AM

Panarchy, is there a reason you don't write a generic program that can accept the IP address as a parameter?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#34 ikonia

ikonia

    CC Newcomer

  • Just Joined
  • PipPip
  • 22 posts

Posted 25 July 2009 - 06:06 AM

because all his requests are "could someone do this for me"
  • 0

#35 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 25 July 2009 - 05:05 PM

Panarchy, is there a reason you don't write a generic program that can accept the IP address as a parameter?


Because I obviously don't know how.

:S
  • 0

#36 dargueta

dargueta

    I chown trolls.

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

Posted 25 July 2009 - 05:08 PM


#include <string>

using std::string;



int main(int argc, char **argv)

{

    string arg1 = argv[1];

    string arg2 = argv[2];

    ...

}


  • 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