Search code examples
pythonprintingnslookup

Program is printing memory values instead of actual values


Kind of got into a bit of a brain stump here. I was using the nslookup package and i wanted to get the ip address of a domain (in this case google). When I run the code below, i get an output of: "<nslookup.nslookup.DNSresponse object at 0x00000204C9001548>" instead of the ip address.

Code:

import nslookup

theLook = nslookup.Nslookup()

print(theLook.dns_lookup(domain="google.com"))

Yes, i know this is probably a stupid question but i swear, ive been searching for an answer and couldn't find one for my case. I also think i may have been able to solve this before but i can't remember how. Thanks for any answers.


Solution

  • You are asking to print an object, which calls the internal __repr__ of the Nslookup(). The response is in the .answer attribute, so :

    print(theLook.dns_lookup(domain="google.com").answer)
    

    should do what you need.

    The documentation provides more details too: https://pypi.org/project/nslookup/

    Returns an object containing two arrays:

    response_full: the full DNS response string(s)

    answer: the parsed DNS answer (list of IPs or SOA string)