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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, goBoating, please reply me!!

Status
Not open for further replies.

cgi

Programmer
Feb 15, 2001
6
SG
hi
i want to say thank you to
the code which you give me can work.

i need to save all the ip addresses in a network into a txt file
the execute the fping to read from that file and fping those ip addresses.
can i make the fping script to run automatic??
 
OK,....one more shot. But, the support you are requesting is fairly basic stuff. I don't mind helping, but, you need to gain a few basic skills and there are plenty of resources available to do that. Please buy ( or check out from a library) two books and start reading. The first is "Teach Yourself PERL 5 in 21 Days", published by SAMS. This is a good starter for someone who knows little or no Perl. It has clear examples and a good approach to presenting the material. You will quickly learn enough in this book to begin putting together functional, useful code. The second is "Programming Perl" by Wall, Christiansen, and Schwartz, pulished by O'Reilly( This is the Perl BIBLE (or Koran or whatever....). The examples are a little complex sometimes, so it makes it a difficult resource for the beginner. But, once you figure out how to spell Perl, you will wear this book out as a reference. Each book has it's short comings, but they compliment each other well for a newbie Perl library.

Sorry about the sermon,
On to the code.....

Create your text file containing the IP addresses.
### text file named => 'IPs.txt' ###
123.456.789.123
123.456.789.124
123.456.789.125
123.456.789.126
123.456.789.127
123.456.789.128
### end text file ###

Code:
#!/usr/local/bin/perl

# open an output file to record the results
open(OPF,">fping_results.txt") or die "Failed to open OPF, $!\n";

# read each IP address from the text file and run fping
open(IPF,&quot;<IPs.text&quot;) or die &quot;Failed to open input file, $!\n&quot;;
while (<IPF>) 
    {
    chomp; # remove \n and \r as needed.
    print OPF &quot;\n\n$ip - \n&quot;;
    # open a pipe (child process) for the fping
    open(PIPE,&quot;fping $ip |&quot;) or die &quot;Failed to open PIPE to $cmd, $!\n&quot;;
    while(<PIPE>) { print OPF &quot;$_&quot;; }
    close PIPE;
    }
    
close IPF;
close OPF;

I have not run this.... but, it should be pretty close.

Good Luck,
HTH


keep the rudder amid ship and beware the odd typo
 
Another book thats helped me a ton is Learning Perl, by O'Reilly. It gives you great homework assignments.

Chief Joseph
 
The Perl Cookbook is really great too so many examples and new ideas it is great for anyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top