Solved

Ping in perl

Posted on 2003-11-10
13
1,166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…

730 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