CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Modified

 



bobbyperl
Novice

Apr 19, 2006, 8:02 AM

Post #1 of 13 (1539 views)
Modified Can't Post

Hi ok some great people in here got a pece of code working for me earlier ,



I now need to mod it so it works with domains and ips that are not serving web pages



use LWP::Simple;
@hosts = ("");
print "Content-type: text/html\n\n";
foreach $host(@hosts){
if (head($host)){
print "$host ... Server Is Up And Running \n"; }
else { print "$host ... Error Server Is Down\n";
}
}



This is great it checks the host but if i put in a ip of server that isit sering web pages like a dns server it doesnt work .



Is there away of pinging the server and gettting results .


d1zz13
User

Apr 19, 2006, 9:08 AM

Post #2 of 13 (1534 views)
Re: [bobbyperl] Modified [In reply to] Can't Post

You might be better off using a module like Net::Ping for this one.

Once you've established that the server itself is up, then you can worry about if it's serving the content it's meant to be.

Maybe a parameter csv file with a format of network name and box function, something like this:

Code
micky,web 
donald,web
minnie,dns
goofy,mail


You run a standard bit of code using Net::Ping which returns the response as to if the server's up or not (it can use six different protocols to check) and then once you know the hardware is physically responding, based on the value in the parameter file you check to see if it's serving the content.

You'd use LWP for both micky and donald, maybe Net::DNS for minnie and a quick search of CPAN should give you some ideas for how to query goofy.

Regards
Rich


bobbyperl
Novice

Apr 19, 2006, 9:21 AM

Post #3 of 13 (1532 views)
Re: [d1zz13] Modified [In reply to] Can't Post

Ok this is sweet man , I think im rushing the perl to muich i have tried to use the net ping command but didnt understand the 5 parts now uve sort of explained more .

I find it easier to learn in here than from the book as this place has many of Q's and A's

Il have a go and let u no what i have done


d1zz13
User

Apr 19, 2006, 10:35 AM

Post #4 of 13 (1527 views)
Re: [bobbyperl] Modified [In reply to] Can't Post


In Reply To
I'll have a go and let u no what I have done

You'll always earn more respect by searching the web, forums, having a go, and then posting. That way it shows you're interested in finding out the answer and not just getting the code written for you.

Well done.
Rich


bobbyperl
Novice

Apr 20, 2006, 2:18 AM

Post #5 of 13 (1520 views)
Re: [d1zz13] Modified [In reply to] Can't Post

Hey guys had a look at this NET::DNS and i seem to notice there are like 9 options i can use



I think this is the bit i need to play with to get it working ,


Code
use Net::DNS; 
my $res = Net::DNS::Resolver->new;
my $query = $res->search("host.example.com");
if ($query) {
foreach my $rr ($query->answer) {
next unless $rr->type eq "A";
print $rr->address, "\n";
}
} else {
warn "query failed: ", $res->errorstring, "\n";
}


i took this from an example site i can probally try figure out how to use this if its the right sort of way


(This post was edited by davorg on Apr 21, 2006, 6:36 AM)


davorg
Thaumaturge / Moderator

Apr 21, 2006, 6:38 AM

Post #6 of 13 (1510 views)
Re: [bobbyperl] Modified [In reply to] Can't Post

Do you want to get DNS records for the servers? I would think that Net::Ping might be more useful for you.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


bobbyperl
Novice

Apr 21, 2006, 6:46 AM

Post #7 of 13 (1509 views)
Re: [davorg] Modified [In reply to] Can't Post

Basically my aim is i have about 12 servers all over the place some dns some web servers some samba and so on . What i need to do is be able to tell that they are all runing , Like if u look at the first post some great guys on here got that bit going for me . Thats all cool and checks ips andweb pages but what i found if i put my dns server in or my samba ip in it fails . I belive the reason for this is the code we used first only works on web servers or things serving web pages.

I dont no per very well at all and am trying to get my head aroudn it .


davorg
Thaumaturge / Moderator

Apr 21, 2006, 7:22 AM

Post #8 of 13 (1508 views)
Re: [bobbyperl] Modified [In reply to] Can't Post

Oh, I know what's going on. I've been involved in some of it.

So. You have a number of servers that perform various functions and you need to test if a) each server is alive and b) if it's performing the function it's supposed to perform.

I suggest that you use Net::Ping to check the first part (strictly, that will check that the server is alive and that you have network connectivity to the server - but that's the best you can reasonably expect) and only if that test is successful then you should go on and check the second part.

To check for various network functions, the best way is obviously to make a request to the server and see if you get a response. For web servers you obviously make an HTTP request as we did earlier in the week.

For DNS servers it will be a little harder. You have to understand the difference between requesting the DNS details for a server and running DNS queries on a server. You need the latter. Net::DNS allows you to specify a particular nameserver when creating a resolver object - that's what you need to use.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


d1zz13
User

Apr 21, 2006, 7:46 AM

Post #9 of 13 (1507 views)
Re: [davorg] Modified [In reply to] Can't Post

FINALLY... One of my posts is actually backed up by a respected expert... Cheers Dave. Smile

Regards
Rich

If it aint broke then don't try to fix it


davorg
Thaumaturge / Moderator

Apr 21, 2006, 7:56 AM

Post #10 of 13 (1506 views)
Re: [d1zz13] Modified [In reply to] Can't Post


In Reply To
a respected expert


Can I quote you on that :-) ?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


d1zz13
User

Apr 21, 2006, 8:17 AM

Post #11 of 13 (1504 views)
Re: [davorg] Modified [In reply to] Can't Post

You just did :-)

Regards
Rich

If it aint broke then don't try to fix it


bobbyperl
Novice

Apr 21, 2006, 8:34 AM

Post #12 of 13 (1503 views)
Re: [davorg] Modified [In reply to] Can't Post

hank you for the reply i will tryt and look up more on this now i have an idea i will be back later or tommrow to show u were i have gotten


MrPJ
User

Apr 22, 2006, 2:11 AM

Post #13 of 13 (1499 views)
Re: [d1zz13] Modified [In reply to] Can't Post


In Reply To
FINALLY... One of my posts is actually backed up by a respected expert... Cheers Dave. Smile


That's a matter of opinion ;)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives