School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,440 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,504 people online right now. Registration is fast and FREE... Join Now!




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

 

HELP: Script to gather IP Address from .RDP then compile to .exe for V, gather the IP Address & Name from .RDP or .vRD files, then input b

Panarchy

5 Jun, 2009 - 06:51 PM
Post #1

D.I.C Head
**

Joined: 28 Nov, 2007
Posts: 81


My Contributions
Hi

I need some help creating a script that can gather IP Address from within .RDP or .vRD files, then output to the IP Address to a text file.

I then need that IP Address from that text file to be automatically inputted into a .cpp file, subsequently compiled and given the same name as the .RDP or .vRD file.

The .cpp file is basically a batch file (without the Command-Prompt window) which launches vnc viewer (UltraVNC) with username and password, unlike .VNC files which are limited to password ONLY authentication. This dual authentication is achieved using the following;
vncviewer.exe /connect xx.xx.xx.xx:5900 /user USERID /password PASSWORD

lscrat was used to do the /connect etc.

Please give me an example of a script which can gather the IP Address & Name from .RDP or .vRD files, then input both the IP Address & Name into a logfile, subsequently copying the IP Address into a .cpp file, compiling it, then renaming the *.exe to the name which correlates to the IP Address.

Thanks in advance,

Panarchy

User is offlineProfile CardPM
+Quote Post


Panarchy

RE: HELP: Script To Gather IP Address From .RDP Then Compile To .exe For V

22 Jun, 2009 - 06:20 AM
Post #2

D.I.C Head
**

Joined: 28 Nov, 2007
Posts: 81


My Contributions
Greetings

I would like to update you on what progress has been made. The code is not yet complete, but if you have the time, and knowledge, could you please help me complete the script?

Here's what's been done so far;

CODE
#!/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);

#exit
1;


The above code is written in Perl, and is almost complete.

What the complete code should be able to do is;

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
[Then Loops]


Please help me complete the above code, or write some new code which completes the above steps.

Thanks in advance,

Panarchy

Sample CSV File: Book1.csv
Code::Blocks project: VNC.zip
Visual Studio 2008 project: VNC.zip
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:12AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month