Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Ping in perl

Posted on 2003-11-10
13
Medium Priority
?
1,179 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

618 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