there is a dns modul for Python (I don't know is it part of standard Python library or not), on most Linux distribution you can find it, eg. in Debian it's called python-dnspython.
It can handle different nameserver, than OS knows - here is a sample code:
import dns.resolver
r = dns.resolver.Resolver()
r.namerservers = ['127.0.0.1']
mxservers = r.query("python.org", 'MX').response