Last active
October 19, 2017 20:04
-
-
Save felixhummel/8721871 to your computer and use it in GitHub Desktop.
DEPRECATED. See https://github.com/felixhummel/bin/blob/master/dnsexpire.py
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 : | |
""" | |
Prints the expiration time of a domain as seen from the host this is run on. | |
Example Output: | |
felixhummel.de (37.200.98.98): 3055 sec (about 50 min) | |
""" | |
from __future__ import print_function | |
import calendar | |
import time | |
import sys | |
def _exit1(msg): | |
print(msg, file=sys.stderr) | |
raise SystemExit(1) | |
try: | |
import dns.resolver | |
except ImportError: | |
_exit1('Please install dnspython, e.g. ``pip install --user dnspython``') | |
def remain(domain): | |
""" | |
:return: A tuple containing (ip, remaining_seconds) | |
""" | |
x = dns.resolver.query(domain) | |
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__': | |
if len(sys.argv) < 2: | |
_exit1('Usage: dns_expire <domain>...') | |
domains = sys.argv[1:] | |
main(domains) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment