Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7123 > unrolled thread
| Started by | Eric <eric.wong.t@gmail.com> |
|---|---|
| First post | 2011-06-06 17:40 -0700 |
| Last post | 2011-06-07 21:46 +0100 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.python
Validating string for FDQN Eric <eric.wong.t@gmail.com> - 2011-06-06 17:40 -0700
Re: Validating string for FDQN harrismh777 <harrismh777@charter.net> - 2011-06-06 20:55 -0500
Re: Validating string for FDQN Chris Angelico <rosuav@gmail.com> - 2011-06-07 12:50 +1000
Re: Validating string for FDQN Philip Semanchuk <philip@semanchuk.com> - 2011-06-06 23:10 -0400
Re: Validating string for FDQN Nobody <nobody@nowhere.com> - 2011-06-07 06:23 +0100
Re: Validating string for FDQN Chris Angelico <rosuav@gmail.com> - 2011-06-07 15:52 +1000
Re: Validating string for FDQN Chris Torek <nospam@torek.net> - 2011-06-07 06:20 +0000
Re: Validating string for FDQN Nobody <nobody@nowhere.com> - 2011-06-07 21:46 +0100
| From | Eric <eric.wong.t@gmail.com> |
|---|---|
| Date | 2011-06-06 17:40 -0700 |
| Subject | Validating string for FDQN |
| Message-ID | <d30814aa-494f-457f-8a56-5ebe802f4725@z7g2000prh.googlegroups.com> |
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. Thanks.
[toc] | [next] | [standalone]
| From | harrismh777 <harrismh777@charter.net> |
|---|---|
| Date | 2011-06-06 20:55 -0500 |
| Message-ID | <nyfHp.974$SG4.690@newsfe03.iad> |
| In reply to | #7123 |
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.
You might try the os module and then use something like nslookup.
import os
os.system('nslookup <name>')
The output is sent on the subprocess standard out... so you can grab it
with piping, or redirect, or redirect to a file and read later, etc.
You might also try the subprocess module. It provides better flexibility
and control for handling the output of the nslookup, or whatever tool
you decide to use to find the fully qualified name.
kind regards,
m harris
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-06-07 12:50 +1000 |
| Message-ID | <mailman.2516.1307415025.9059.python-list@python.org> |
| In reply to | #7123 |
On Tue, Jun 7, 2011 at 10:40 AM, Eric <eric.wong.t@gmail.com> 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
[toc] | [prev] | [next] | [standalone]
| From | Philip Semanchuk <philip@semanchuk.com> |
|---|---|
| Date | 2011-06-06 23:10 -0400 |
| Message-ID | <mailman.2519.1307419368.9059.python-list@python.org> |
| In reply to | #7123 |
On Jun 6, 2011, at 8:40 PM, 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. The ones here served me very well: http://pyxml.cvs.sourceforge.net/viewvc/pyxml/xml/xml/Uri.py?revision=1.1&view=markup bye Philip
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-06-07 06:23 +0100 |
| Message-ID | <pan.2011.06.07.05.23.21.453000@nowhere.com> |
| In reply to | #7123 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-06-07 15:52 +1000 |
| Message-ID | <mailman.2521.1307425928.9059.python-list@python.org> |
| In reply to | #7137 |
On Tue, Jun 7, 2011 at 3:23 PM, Nobody <nobody@nowhere.com> wrote: > [1] If a hostname ends with a dot, it's fully qualified. > Outside of BIND files, when do you ever see a name that actually ends with a dot? ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Chris Torek <nospam@torek.net> |
|---|---|
| Date | 2011-06-07 06:20 +0000 |
| Message-ID | <iskg0503lq@news5.newsguy.com> |
| In reply to | #7138 |
>On Tue, Jun 7, 2011 at 3:23 PM, Nobody <nobody@nowhere.com> wrote: >> [1] If a hostname ends with a dot, it's fully qualified. [otherwise not, so you have to use the resolver] In article <mailman.2521.1307425928.9059.python-list@python.org>, Chris Angelico <rosuav@gmail.com> wrote: >Outside of BIND files, when do you ever see a name that actually ends >with a dot? I type them in this way sometimes, when poking at network issues. :-) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2011-06-07 21:46 +0100 |
| Message-ID | <pan.2011.06.07.20.45.52.953000@nowhere.com> |
| In reply to | #7138 |
On Tue, 07 Jun 2011 15:52:05 +1000, Chris Angelico wrote: >> [1] If a hostname ends with a dot, it's fully qualified. > > Outside of BIND files, when do you ever see a name that actually ends > with a dot? Whenever it is entered that way. This may be necessary on complex networks with local subdomains, i.e. where resolv.conf has "options ndots:2". E.g. "foo.it" might resolve to "foo.it.bar.edu" (in bar.edu's IT department's subdomain), requiring a trailing dot if you want the Italian site "foo.it". The canonical real-world example of this used to be foo.cs resolving to foo.cs.berkeley.edu (UCB Comp. Sci. department), but ever since .cs split into .cz and .sk it's no longer ambiguous.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web