Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!tudelft.nl!txtfeed1.tudelft.nl!dedekind.zen.co.uk!zen.net.uk!hamilton.zen.co.uk!shaftesbury.zen.co.uk.POSTED!not-for-mail From: Nobody Subject: Re: Validating string for FDQN Date: Tue, 07 Jun 2011 06:23:30 +0100 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-Id: Newsgroups: comp.lang.python References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lines: 14 Organization: Zen Internet NNTP-Posting-Host: 51589275.news.zen.co.uk X-Trace: DXC=cRL]COKXPJPe\eJLPTb1h^nok4Z\3cB^f=ZQOMCU8L]ShW1gDN2:TE2lS X-Complaints-To: abuse@zen.co.uk Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7137 On Mon, 06 Jun 2011 17:40:29 -0700, Eric wrote: > Is there a library or regex that can determine if a string is a fqdn > (fully qualified domain name)? I'm writing a script that needs to add > a defined domain to the end of a hostname if it isn't already a fqdn > and doesn't contain the defined domain. Try socket.getfqdn() or socket.gethostbyname_ex(). With one exception[1], you can't reliably do it just by examining the string; you have to ask the resolver. [1] If a hostname ends with a dot, it's fully qualified.