Re: [exim] Detecting the domain part of a host address

Etusivu
Poista viesti
Vastaa
Lähettäjä: Arthur Hagen
Päiväys:  
Vastaanottaja: exim-users
Aihe: Re: [exim] Detecting the domain part of a host address
On Mon, 2007-06-25 at 07:17 -0700, Marc Perkel wrote:
>
> OK let me rephrase the question. What I want is to start with a
> $sender_host_name and get a string that ends with the TLD and is
> preceded by the next string back to the period.
>
> In this example:
>
> mx.cam.ac.uk
> virgo.cus.cam.ac.uk
> ewe.damtp.cam.ac.uk
>
>
> All of these would return cam.ac.uk


That doesn't match your requirement. The TLD is .uk, not ac.uk

The thing is that DNS relegation is a tree structure, and you can not
know how many branches there are. nic.museum is a valid host in (and MX
for) the .museum TLD (not that many mail programs let you send emails to
hostmaster@museum), and oxmail.ox.ac.uk is a valid host in (and MX for)
the ox.ac.uk zone.

But there's no way to decide the domain a particular host belongs to,
except the very outermost one which you get by stripping the hostname.
How about these? Where, exactly would you split them, and what would
the rule be?

foo.1.0.168.192.bar.baz.furple.example
foo.bar.baz.furple.example
foo.baz.furple.example
foo.furple.example
foo.example

> I don't care to argue about why I want it. I just want it. I just want
> the next part before the TLD.


The TLD is the last part, like .uk and .com. ac.uk is not a TLD. If
you mean second level domain, there's no guarantee that there is one.
Your vanity domain, perkel.com, doesn't have one.

If you meant what you said, and not what your example indicated, and you
want "ac" for oxmail.ox.ac.uk and nic for nic.museum or any similarly
fixed position part, then that's trivial enough to extract:

echo "oxmail.ox.ac.uk" | perl -pe 'split /\./; $_=$_[$#_-1]'
ac

Regards,
--
*Art