Created
July 19, 2013 13:41
-
-
Save felixhummel/6039174 to your computer and use it in GitHub Desktop.
Prints IP address and expiration time for a domain. See first comment for usage.
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
#!/usr/bin/env python | |
# vim: set fileencoding=utf-8 filetype=python : | |
""" | |
Usage: dns_expire <domain>... | |
""" | |
import calendar | |
import time | |
import dns.resolver | |
from docopt import docopt | |
def remain(domain): | |
x = dns.resolver.query(domain) | |
now = calendar.timegm(time.gmtime()) | |
ip = x.response.answer[0][0].address | |
remaining = x.expiration - calendar.timegm(time.gmtime()) | |
return ip, remaining | |
def main(domains): | |
for domain in domains: | |
ip, remain_sec = remain(domain) | |
if remain_sec < 60: | |
print '%s (%s): %d sec' % (domain, ip, remain_sec) | |
else: | |
print '%s (%s): %d sec (about %.1d min)' % (domain, ip, remain_sec, remain_sec / 60.0) | |
if __name__ == '__main__': | |
args = docopt(__doc__) | |
domains = args['<domain>'] | |
main(domains) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires dnspython and docopt.