Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read info from a txt file and use content into commands... 1

Status
Not open for further replies.
Oct 8, 2007
2
US
Quick situation:

1. I am not a coder, nor do I pretend to be one :)
2. I use the same tools a lot, and for the sake of consistency, I decided to script their use using perl
3. As of yesterday, I knew nothing about perl
4. I created my first script which automates scans using nikto, nmap and nessus.
5. As part of the script, a text file is created using nano. Each line contains one IP address and that's it.
6. Some of the tools I use can refer to a "target file" and parse it themselves. Some cannot.
7. For those that cannot, I want perl to look at that file, and basically "feed" it line by line to the over all tool command so that it can scan each IP address separately.
8. Darn if I can do what #7 says :)

So basically, if I have a command that goes like this:

tool <targetip>

I want for perl to look at the defined target file.txt, and grab each IP address one by one, and feed it into the command above... I hope I am making sense.

Thanks for any help you may be able to bring me on this!

PS: good thing I am not a coder by trade... my kids would go hungry many a night...
 
not tested in any way..

$file = '/path/to/file';
$program = `/path/to/program`;
open(FILE, "<$file") or die "Can't open $file:$!\n";
while(<FILE>){
`$program $_`;
}
close FILE;

those are backticks by the way. You can look up system calls for more info on those.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
assumes one ip per line of file;

Code:
open(FH,'filename') or die "$";
while(<FH>){
   chomp;
   tool($_);
}
close FH;

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
or die "$";
is that right??
I've always used $!
but it's rare that your wrong.. so do some explainin!! :D

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
It's a first Travis - But I think our Kevin's actually wrong :)

Mike

When working on any project the value of other people is exactly that - they are other people. The mismatch between their views and the view you've been contentedly assuming is right, is where that value lies.
 
Oops.... Should be: $!

Thanks Travs.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I really thought I just didn't know something. Every time I see something new I like to question it as the main reason I'm here is to learn!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Thanks guys, this is great help. I really appreciate it. Funny when us pen testers pretend to be coders out of necessity... boy do I have a ton to learn!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top