Solved

Ping in perl

Posted on 2003-11-10
13
1,164 Views
Last Modified: 2008-03-10
Hi,

how do you ping using perl? I know I can use bash by doing ` ` but how would I do it?

is it - Print "`ping` $ipAddress"

and how do I press return? `/r`?

Thanks.
0
Comment
Question by:Paulmul
13 Comments
 
LVL 49

Expert Comment

by:sunray_2003
ID: 9714540
0
 
LVL 1

Author Comment

by:Paulmul
ID: 9714993
That's not really what I need. Pinging isn't the important part, its just something I need to do, I need to know how to use bash and perl to ping an IP, it HAS to be done that way.
0
 
LVL 1

Author Comment

by:Paulmul
ID: 9715039
I worked out how to do what I needed.

Code is


print "Enter URL";
$url = <stdin>;
chomp $url;

$res = `ping "$url"`;

print "$res";
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 20

Expert Comment

by:jmcg
ID: 9715335
There are quite few questions in the database with examples of how to use Net::Ping.

http://www.experts-exchange.com/Q_20185876.html

http://www.experts-exchange.com/Q_20606541.html

But if they don't answer your question sufficiently, let us know here and we can try to be more clear.
0
 

Expert Comment

by:acameron
ID: 9715356
I like:

@results = qx/ping $OPTIONS $HOST/;
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9715831
Rather than delete, I recommend PAQ, but still refund points. Paulmul's solution is okay, and may be what is required for his situation, but it's important for askers to consider the "pure perl" approaches that do not explicity call out to external programs.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 9718438
Here's a ksh and Perl (shellified version)

#!/bin/ksh
print "Enter URL"
read url

res=`ping $url`
print "$res"

#!/usr/bin/perl
print "Enter URL";
$url=<STDIN>;

$res=`ping $url`;
print "$res";

However, some points to make:

You can't ping URL's, you can only ping IP addresses or hostnames (that resolve to an IP address).  
I see no point in writing a shell script as a Perl script.  If you are going to write a Perl script, write it as Perl not a pseudo shell script (one of my particular hobby horses).
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9718861
AnnieMod, Agreed. ***Always read very carefully what the moderator posts.***

I had read the user's request to delete and failed to notice exactly which boilerplate notice you had responded with. Sorry.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9719169
It's been an active thread. Several people, including me, have posted something they wrote only to discover that more details had arrived while they were researching and writing.

Keep up the good work, everyone!
0
 

Accepted Solution

by:
SpazMODic earned 0 total points
ID: 9743084
PAQed, with points refunded (50)

SpazMODic
EE Moderator
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl count the hash for print 4 165
what are these modules in perl script 4 99
perl: Cleaning meta tags using RegEX 12 79
Log File Creation with Header and Footer 17 95
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question