Solved

Ping in perl

Posted on 2003-11-10
13
1,165 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

831 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