473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

When i ping 3 ipaddress in my code, only the 3rd ip is pinging? what is the error?

Expand|Select|Wrap|Line Numbers
  1. !/usr/bin/perl
  2.  
  3. #To check the servers can able to ping or not
  4. print " ENTER THE NUMBER OF SERVERS \n";
  5.  
  6. $servers = <STDIN>;
  7.  
  8. for ( $i = 1 ; $i <= $servers ; $i++ ) {
  9.     print "ENTER THE SERVER $i IP ADDRESS \n";
  10.     $i[a] = <STDIN>;
  11. }
  12.  
  13. use Net::Ping;
  14.  
  15. $p = Net::Ping->new();
  16.  
  17. for ( $i = 1 ; $i <= $servers ; $i++ ) {
  18.     if ( $p->ping("$i[a]") ) {
  19.         print "$i[a] \n PING IS SUCESSSSSS!!!! \n";
  20.     } else {
  21.         print "$i[a] \n \a REQ TIMED OUT \n";
  22.     }
  23. }
  24.  
#In this perl code, im getting the input as ip address from the user and pinging it. when i compile and run this code, say when i get 3 ipaddress from the user only my 3rd ip is pinging. So could you please tell me what is the error?
Apr 5 '11 #1
4 1678
Rabbit
12,516 Expert Mod 8TB
You're using the same variable for as both the array and counter? You should probably use different variables. Also, you're not incrementing your array index.
Apr 5 '11 #2
miller
1,089 Expert 1GB
You're code is full of errors with regard to your variables. Add use strict; and use warnings to the start of your script.

After you fix all the errors adding those lines will report to you, repost your code and we can help you from there.
Apr 5 '11 #3
#In this perl code, im getting the input as ip address from the user and pinging it. when i compile and run this code, say when i get 3 ipaddress from the user only my 3rd ip is pinging. So could you please tell me what is the error?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #To check the servers can able to ping or not
  3.  
  4. print " ENTER THE NUMBER OF SERVERS \n";
  5.  
  6. my $servers=<STDIN>;
  7.  
  8. for($i=1; $i<=$servers; $i++){ 
  9.     print "ENTER THE SERVER $i IP ADDRESS \n";
  10.     $i[a]=<STDIN>;
  11. }
  12.  
  13. use Net::Ping;
  14.  
  15. $p=Net::Ping->new();
  16.  
  17. for( $i=1; $i<=$servers; $i++) {
  18.     if($p->ping("$i[a]")) {
  19.         print "\n PING IS SUCESSSSSS!!!! \n";
  20.         print "$i[a] \n";
  21.  
  22.     } else {
  23.         print "\n \a REQ TIMED OUT \n";
  24.         print "$i[a] \n";
  25.     }
  26. }
  27.  
Apr 6 '11 #4
miller
1,089 Expert 1GB
dawood munavar,

I've merged your threads asking the same question. Please continue your work on this issue in this thread.

You still haven't followed the advice that I gave you originally. Change the beginning of your script to the following:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. #To check the servers can able to ping or not
  3.  
  4. use strict;
  5. use warnings;
  6.  
After you fix all the errors that will report to you, then repost your code and we can help you.

Regards,
- Miller
Apr 6 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Max Harvey | last post by:
Hi, I have looked at the example called "Open Parameter queries from code" from the site http://www.mvps.org/access/queries/qry0003.htm I made up a test which I though looked pretty close...
17
by: wana | last post by:
I was reading through original source code of ping for some insight and was confused by unusual code. Entire listing available at: http://www.ping127001.com/pingpage/ping.html #include...
2
by: Ian Sykes | last post by:
I have a C# program which terminates prematurely, with no error or exception being raised, the termination point varying with what diagnostic code is present. The termination point appears to be...
13
by: Russell Hind | last post by:
I'm trying to use boost::bind and boost::function inside managed code, but there appears to be some code generation problems. The following code compiles fine, but the function object throws an...
0
by: MaxN | last post by:
I'm writing a program to go to a website, extract the source code, parse the code to get the data in the tables, sort the data in a particular manner, write it to a .txt, and send it to our database...
0
by: Santosh | last post by:
Hii, I am developing web application using asp.net with in that i am using crytal report for showing reports. it works fine on local machine but when i deploy it on the web server it gives me key...
7
by: wingsss | last post by:
i am currently using WindowsXP SP2 all updated apache 2.2.4 PHP 5.2.3 MySQL 5.0 and apache hang up when running this code //...
5
by: swarnavplsql | last post by:
In this code ,i think in insert statement select quary returning more than one value, that is only error .....plz tell me any body cursor c1 is select...
6
by: dragiton | last post by:
ASP Code Redirect Error Hello I recently relaunched a website containing asp code which used to work perfectly. However, after resetting up the SQL DB and trying to work out some site bugs I have...
13
by: rjonam | last post by:
What is the reason for Object required Line: 24 Char: 4 Code: 0 error which occurs in IE 7, not in FF...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.