Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #55803

Perl Hacker, Python Initiate

Path csiph.com!eeepc.pasdenom.info!news.pasdenom.info!news.dougwise.org!aioe.org!feeder.news-service.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <gwchamb@gwcmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'skip': 0.04; 'subject:Python': 0.05; 'python?': 0.05; 'onto': 0.07; 'alias': 0.09; 'expressions.': 0.09; 'output': 0.10; 'loop': 0.13; 'linux': 0.14; '$2;': 0.16; '(i.e.': 0.17; 'skip:( 20': 0.22; 'solaris': 0.23; 'perl': 0.24; 'push': 0.24; 'skip:( 40': 0.28; 'unable': 0.28; 'exit': 0.28; 'skip:# 10': 0.28; 'testing': 0.28; 'hostname': 0.30; 'skip:( 60': 0.30; 'skip:@ 10': 0.30; 'stops': 0.30; 'all,': 0.30; 'match': 0.30; 'to:addr:python-list': 0.31; 'thank': 0.31; 'array': 0.32; 'received:192.168.1': 0.32; 'keys': 0.34; 'matches': 0.34; 'received:192': 0.34; 'someone': 0.34; 'header:User-Agent:1': 0.34; 'print': 0.35; 'skip:" 10': 0.35; 'open': 0.36; 'regular': 0.37; 'received:192.168': 0.37; 'charset :us-ascii': 0.37; 'close': 0.37; 'two': 0.38; 'next': 0.38; 'some': 0.39; 'to:addr:python.org': 0.40; 'comments': 0.40; 'address': 0.60; 'received:173': 0.62; 'subject:Hacker': 0.84; 'something.': 0.91
Date Tue, 1 Feb 2011 23:36:27 -0500 (EST)
From Gary Chambers <gwchamb@gwcmail.com>
X-X-Sender gwc@localhost
To python-list@python.org
Subject Perl Hacker, Python Initiate
User-Agent Alpine 2.01 (OSX 1266 2009-07-14)
MIME-Version 1.0
Content-Type TEXT/PLAIN; format=flowed; charset=US-ASCII
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1576.1296621817.6505.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 82.94.164.166
X-Trace 1296621817 news.xs4all.nl 41103 [::ffff:82.94.164.166]:40743
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:55803

Show key headers only | View raw


All,

Given the following Perl script:

#!/usr/bin/perl

%dig = (
     solaris => "/usr/sbin/dig",
     linux   => "/usr/bin/dig",
     darwin  => "/usr/bin/dig"
);

$DIG = $dig{"$^O"};
$DOMAIN = "example.com";
$DNS = "ns.example.com";
$DIGCMD = qq/$DIG \@$DNS $DOMAIN axfr/;

open DIG, "$DIGCMD|" or die "$DIG: $!\n";
while (<DIG>) {
     next if (/^;/); # Skip any comments
     # If we match a CNAME record, we have an alias to something.
     # $1 = alias (CNAME), $2 = canonical hostname
     if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.${DOMAIN}\.$/) {
         # Push an alias (CNAME) onto an array indexed on canonical hostname
         push(@{$cnames{$2}}, $1);
     }
     # Here's a standard A (canonical hostname) record
     # $1 = canonical hostname, $2 = IPv4 address
     if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*A\s+(\S+)$/) {
         $ip{$1} = $2;
     }
}
close DIG;

# Format and display it like niscat hosts:
# canonicalHostname alias1 [alias2 aliasN] ipAddress
for $host (sort keys %ip) {
     print "$host ";
     if (defined(@{$cnames{$host}})) {
         print join(' ', @{$cnames{$host}});
         print " ";
     }
     print "$ip{$host}\n";
}
exit 0;

Will someone please provide some insight on how to accomplish that task in
Python?  I am unable to continually (i.e. it stops after displaying a single
line) loop through the output while testing for the matches on the two
regular expressions.  Thank you.

-- Gary Chambers

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Perl Hacker, Python Initiate Gary Chambers <gwchamb@gwcmail.com> - 2011-02-01 23:36 -0500
  Re: Perl Hacker, Python Initiate Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-02-02 10:06 +0000
  Re: Perl Hacker, Python Initiate Ben Finney <ben+python@benfinney.id.au> - 2011-02-02 15:56 +1100
  Re: Perl Hacker, Python Initiate sturlamolden <sturlamolden@yahoo.no> - 2011-02-03 08:12 -0800

csiph-web