Created
November 14, 2012 20:29
-
-
Save ytjohn/4074564 to your computer and use it in GitHub Desktop.
quick hostname reversal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is very useful for sorting hostnames. | |
def revhost(host): | |
""" split a hostname into segments, reverse them, and then rejoin them """ | |
segments = host.split('.') | |
segments.reverse() | |
reversed = ".".join(segments) | |
return reversed | |
domain = 'a.ns.example.com' | |
rdomain = revhost(domain) | |
print domain, rdomain | |
# a.ns.example.com com.example.ns.a | |
ndomain = revhost(rdomain) | |
print domain, ndomain | |
# a.ns.example.com a.ns.example.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment