You are not logged in.

#1 2013-05-13 01:53:44

dok
Member
Registered: 2013-02-18
Posts: 13

Perl Pacman Ping

I am writing a Perl utilty to check for dead mirrors in the pacman mirrorlist.

The Net::Ping module seems to be working, but due to some symantics the live servers are being labeled dead.

http://hastebin.com/torekataci.pl
(sorry for the ugly formatting, it was rushed)

Offline

#2 2013-05-13 02:11:23

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Perl Pacman Ping

What is your question? Your script appears to have larger problems than live servers being labelled as dead. For starters, on my machine it truncates the hostnames:

Use of uninitialized value $1 in string at ./test.pl line 15, <LIST> line 1.
dead mirror: 
Use of uninitialized value $1 in string at ./test.pl line 15, <LIST> line 2.
dead mirror: 
Use of uninitialized value $1 in string at ./test.pl line 15, <LIST> line 3.
dead mirror: 
Use of uninitialized value $1 in string at ./test.pl line 15, <LIST> line 4.
dead mirror: 
Use of uninitialized value $1 in string at ./test.pl line 15, <LIST> line 5.
dead mirror: 
Use of uninitialized value $1 in string at ./test.pl line 15, <LIST> line 6.
dead mirror: 
dead mirror: on.net/pub
dead mirror: net.au/pub
dead mirror: edu.au/pub
dead mirror: edu.au

EDIT:
Consider using Regexp::Common

use warnings;
use strict;
use Net::Ping;
use Regexp::Common qw /URI/;;
my @servers;
my $serverso = 0;
my $mirror;
my $p = Net::Ping->new();
open LIST, "/etc/pacman.d/mirrorlist" or die "Mirrorlist not found. Is pacman properly installed?";
 
while(<LIST>)
{
  m|Server = $RE{URI}{HTTP}{-keep}|i or next;
  $mirror = $3;
 
  print "dead mirror: $mirror\n" unless $p->ping($mirror);
  die;
}

close(LIST);

Last edited by fukawi2 (2013-05-13 02:20:25)

Offline

#3 2013-05-13 02:22:31

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: Perl Pacman Ping

1) Your regex is overconstrained. Not every mirror will match m'http://.*\.(.*\..*)/.*linux/' and of the ones that do, the parens will still capture the wrong thing sometimes.
2) Whether or not a server responds to ping is really a different question from whether it services HTTP requests. Some mirrors will not respond to ping, but that does not mean they are dead. Similarly, some servers might respond to being pinged, but that doesn't mean they host Arch mirrors. You need to change your methodology to test the thing you're actually curious about (by downloading the directory list or something).

Offline

#4 2013-05-24 09:21:44

ap0calypse
Member
From: Austria
Registered: 2012-03-12
Posts: 54
Website

Re: Perl Pacman Ping

Please keep in mind, that it maybe uses TCP-Pings instead of ICMP. Maybe that's your problem smile


projects: whistle | bazinga
open minds, open sources, open future.

Offline

Board footer

Powered by FluxBB