Skip to content

Instantly share code, notes, and snippets.

@felixhummel
Created July 19, 2013 13:41
Show Gist options
  • Save felixhummel/6039174 to your computer and use it in GitHub Desktop.
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.
#!/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)
@felixhummel
Copy link
Author

Requires dnspython and docopt.

sudo pip install dnspython docopt
\curl -L https://gist.github.com/felixhummel/6039174/raw/57f3bd7d58a1a40a6f42bcb5126b096dd03fccd3/dns_expire.py | python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment