-1

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.

desertnaut
  • 57,590
  • 26
  • 140
  • 166

2 Answers2

3

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)

juanpa.arrivillaga
  • 88,713
  • 10
  • 131
  • 172
lejlot
  • 64,777
  • 8
  • 131
  • 164
0

but you may also access the dict to get more details

import nslookup

theLook = nslookup.Nslookup()

for x in theLook.__dict__:
    for m in theLook.__dict__[x]:
         print(m)

and you will get output like this

google.com. 151 IN A 74.125.24.102
google.com. 151 IN A 74.125.24.101
google.com. 151 IN A 74.125.24.139
google.com. 151 IN A 74.125.24.138
google.com. 151 IN A 74.125.24.100
google.com. 151 IN A 74.125.24.113
74.125.24.102
74.125.24.101
74.125.24.139
74.125.24.138
74.125.24.100
74.125.24.113