Created
September 25, 2014 08:24
-
-
Save aldarund/bcbb04eb10d3277128b8 to your computer and use it in GitHub Desktop.
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
import dns.resolver | |
import timeit | |
import subprocess | |
import shlex | |
def cmd(cmd, input_data=None): | |
cmd = shlex.split(str(cmd)) | |
popen = subprocess.Popen(cmd, stderr=subprocess.PIPE, | |
stdout=subprocess.PIPE, stdin=subprocess.PIPE, | |
shell=False) | |
stdout, stderr = popen.communicate(input_data) | |
return popen.returncode, stdout, stderr | |
def dnsp_mx(): | |
resolver = dns.resolver.Resolver() | |
resolver.nameservers = ['8.8.4.4',] | |
answers = resolver.query('dnspython.org', 'MX') | |
def dig_mx(): | |
_, out, _ = cmd('dig +short mx @8.8.4.4 dnspython.org') | |
if __name__ == '__main__': | |
print "dnspython %s" % timeit.timeit(dnsp_mx, number=1000) | |
print "dig %s" %timeit.timeit(dig_mx, number=1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment