Closed Thread
Page 7 of 7 FirstFirst ... 567
Results 61 to 70 of 70

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

  1. #61
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

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

    Can't...I'm running Linux.
    sudo rm -rf /

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #62
    Panarchy is offline Programming Professional
    Join Date
    Nov 2007
    Posts
    259
    Rep Power
    0

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

    Ah... WINE?

    lol

    I'll see if the script works, otherwise I'll think of something else...

  4. #63
    Panarchy is offline Programming Professional
    Join Date
    Nov 2007
    Posts
    259
    Rep Power
    0

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

    YAY!

    The script worked

    Thanks a heap!

    Finished product [also changed the res name];
    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);
    @ipfile = <IPFILE>;
    #for each line in the ip file...
    $i = 0;
    $total = 0;
    foreach(@ipfile)
    {
    	#strip leading and trailing spaces off the line
    	my $thisline = $_;
    	chomp($thisline);
    	#use regular expressions to pull the ip address from the line.
    	($currhost,$currip) = split(/\,/,$thisline);
    
        #remove leading and trailing whitespace
        $hostlist[$i] = trim($currhost);
        $iplist[$i] = trim($currip);
    	++$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 = <CPPTEMPLATE>;
    
        #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
        `rc VNC.rc /fo "$currhost.res"`;
        `cl /clr $currhost.cpp`;
        `link VNC.res $currhost.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(@_);
        if(not defined $str){ return ''; }
        $str =~ s/^\s+//;
        $str =~ s/\s+$//;
        return $str;
    }
    EDIT: After testing a few files, found that they were all the same and not portable.

  5. #64
    Panarchy is offline Programming Professional
    Join Date
    Nov 2007
    Posts
    259
    Rep Power
    0

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

    Just double checked everything;

    1. The files aren't portable
    2. All .cpp files are the same, only difference is names. This means that they all have the SAME IP Address.

    Please fix the script.

    Thanks in advance,

    Panarchy

    BTW: Thought it may be helpful, here's the .cpp file again;
    Code:
    // VNC.cpp : Defines the entry point for the application.
    //
    
    #include "stdafx.h"
    #include "resource.h"
    
    #include <windows.h>
    #include <tchar.h>
    #include <iostream>
    
    #ifdef UNICODE
    #define tcout wcout
    #else
    #define tcout cout
    #endif
    
    int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) {
    
    STARTUPINFO si = {0};
        PROCESS_INFORMATION pi = {0};
        TCHAR lpCmdLine[MAX_PATH] = {0};
        ::ExpandEnvironmentStrings(_T("\"%ProgramFiles%\\UltraVNC\\VNCviewer.exe\""),
                                  lpCmdLine, MAX_PATH);
        std::tcout << _T("Command line : ") << lpCmdLine << std::endl;
    
    	lstrcat(lpCmdLine,_T("/connect 127.0.0.1 /user PseudoAd /password Adm#in@!"));
    	  
    	BOOL bRet = ::CreateProcess(NULL, lpCmdLine, NULL, NULL, FALSE,
                                   CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
        return 0;
    
    }

  6. #65
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

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

    I don't see __PUTIPHERE__ anywhere. I think you need to replace 127.0.0.1 with that, if I'm reading your code right. (Doesn't really make sense to remotely log into yourself anyway, at least that I can think of.)
    sudo rm -rf /

  7. #66
    Panarchy is offline Programming Professional
    Join Date
    Nov 2007
    Posts
    259
    Rep Power
    0

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

    Thanks...

    Since I've made some changes, the script no longer works;

    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);
    @ipfile = <IPFILE>;
    #for each line in the ip file...
    $i = 0;
    $total = 0;
    foreach(@ipfile)
    {
    	#strip leading and trailing spaces off the line
    	my $thisline = $_;
    	chomp($thisline);
    	#use regular expressions to pull the ip address from the line.
    	($currhost,$currip) = split(/\,/,$thisline);
    
        #remove leading and trailing whitespace
        $hostlist[$i] = trim($currhost);
        $iplist[$i] = trim($currip);
    	++$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 = <CPPTEMPLATE>;
    
        #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
        `rc VNC.rc /fo "$currhost.res"`;
        `cl /clr $currhost.cpp`;
        `link VNC.res $currhost.obj /out:$currhost.exe`;
        `mt.exe manifest "$currhost".manifest -outputresource:"$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(@_);
        if(not defined $str){ return ''; }
        $str =~ s/^\s+//;
        $str =~ s/\s+$//;
        return $str;
    }
    Any ideas?



    All I've added is more apostrophe's, now situated [where needed] for the $currhost, as the script hadn't been working with spaces. Also added the line to embed the manifest.

    Please point out the problem within the script.

    Thanks in advance,

    Panarchy

  8. #67
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

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

    1) In your call to mt.exe, move the semicolon outside the backticks.
    2) Get rid of the quotes around $currhost, or put them around the entire file name, not just the variable. You shouldn't really need them unless there's a space in the host name. From the CSV file you showed me, it didn't look like there would be any.

    Code:
    #compile
        `rc VNC.rc /fo $currhost.res`;
        `cl /clr $currhost.cpp`;
        `link VNC.res $currhost.obj /out:$currhost.exe`;
        `mt.exe manifest $currhost.manifest -outputresource:$currhost.exe`;
    Last edited by dargueta; 08-06-2009 at 05:02 AM. Reason: Forgot to explain
    sudo rm -rf /

  9. #68
    Panarchy is offline Programming Professional
    Join Date
    Nov 2007
    Posts
    259
    Rep Power
    0

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

    Thanks, I'll give that a go on Monday.

    And yes, the CSV file does have multiple hosts with spaces in them...

  10. #69
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

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

    Ugh. Leave the quotes in, then. Just put them around the entire file name, extension included.
    sudo rm -rf /

  11. #70
    Panarchy is offline Programming Professional
    Join Date
    Nov 2007
    Posts
    259
    Rep Power
    0

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

    Okay, thanks. Will do.

Closed Thread
Page 7 of 7 FirstFirst ... 567

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 04-30-2011, 04:12 PM
  2. [HELP] convert Perl script to Bash shell script
    By Egypte in forum Linux Programming and Scripting
    Replies: 2
    Last Post: 04-24-2011, 05:37 PM
  3. Can't Compile
    By tedmp0816 in forum C and C++
    Replies: 4
    Last Post: 10-20-2009, 01:00 AM
  4. PHP: Gather ALL Post Variables
    By phpforfun in forum PHP Development
    Replies: 7
    Last Post: 01-30-2009, 02:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts