Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!news.ecp.fr!feeder2.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'something,': 0.07; 'hostname': 0.09; 'subject:string': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'defined': 0.14; 'library': 0.15; 'angelico': 0.16; 'domain.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'qualified.': 0.16; 'syntactic': 0.16; 'tld.': 0.16; 'url:tld': 0.16; 'whois': 0.16; 'tue,': 0.17; 'url:code': 0.17; 'header:In-Reply-To:1': 0.21; 'assume': 0.23; 'received:209.85.210.174': 0.23; 'received:mail- iy0-f174.google.com': 0.23; "doesn't": 0.25; 'recognized': 0.26; 'string': 0.26; 'script': 0.27; "i'm": 0.27; 'message- id:@mail.gmail.com': 0.28; 'characters,': 0.30; 'to:addr:python- list': 0.33; 'list': 0.33; "isn't": 0.33; 'chris': 0.34; 'there': 0.35; 'weird': 0.35; 'test': 0.35; 'determine': 0.36; 'probably': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'partial': 0.37; 'hello,': 0.38; 'domain': 0.38; 'url:org': 0.38; 'eric': 0.38; 'too,': 0.38; 'subject:: ': 0.38; 'url:google': 0.38; 'received:209': 0.39; 'add': 0.39; 'to:addr:python.org': 0.39; 'simply': 0.60; 'here:': 0.62; 'url:p': 0.63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=aDzJSfBlRrT4geplAWMgm8vpmdpNMs0aUUCBKtXN2Fg=; b=RhbLxx3Zq4pSbwrInls0yBG1Q+9nRc6SsCDibPgK/McPG2TC+Yl4R0Av7N0UeoPumt 7CVRdXhDfcIfwNOqxUQDJpJ8N+77XkM1NrK3RiWcE2oUVJqzgY/RiEnWGCCHmuzEkyOZ 06Vuj2N+tLVNWF9CT0lauXcVWgYdDuZF+dugU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=HQOH5s9rSKMyPbvG8fHWSJNEFImVufN14J5EjESjqB7IHHh9apHXD3ushePcsUxqq4 E6KzB0/P8ARFFTxP37oI05v8oSPtEurct1KlNpo4S4RXbMv6e4GettWRGCc8s4lZgpto UflQoZqNfQaB/ywutPWNYssdvKKXFnfGgcVAw= MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 7 Jun 2011 12:50:22 +1000 Subject: Re: Validating string for FDQN From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307415026 news.xs4all.nl 49177 [::ffff:82.94.164.166]:44080 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7129 On Tue, Jun 7, 2011 at 10:40 AM, Eric wrote: > Hello, > > 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. One reliable way to test would be to do a whois check on the name. If it comes up with something, it's fully qualified. http://code.google.com/p/pywhois/ Alternatively, if all you want is a simple syntactic check, and if you can assume that the name is already a valid domain name (no weird characters, etc), then you can simply divide it on the last dot and see if the last part is a recognized TLD. A partial list of TLDs can be found here: http://data.iana.org/TLD/tlds-alpha-by-domain.txt There are other TLDs too, including .localhost and .test, which you can probably ignore. Chris Angelico