Solved

Ping in perl

Posted on 2003-11-10
13
1,161 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now