0

I have a program that I wrote that uses this python code called dnstwist which can be found here: Dnstwist documentation

The python code for dnstwist itself can be found here: dnstwist.py

The way my code uses dnstwist is through the os.open() function. It looks like this: s.popen(os.getcwd() + "/dnstwist.py --json --registered " + url).read()

While this does work, I'd prefer to be able to just import dnstwist and use it as a library.

I've looked up some questions here on StackOverflow on how to do such a thing. One in particular: How does Python importing exactly work?

The problem I'm having is that I'm not sure how to call the various functions within dnstwist.

I asked the person who made this how I would do such a thing. They said to do the following:

import dnstwist
fuzz = dnstwist.DomainFuzz("google.com")
fuzz.generate()
fuzz.domains

I tried out this exact code and I got the following error:

AttributeError: 'function' object has no attribute 'DomainFuzz'

I get similar errors any time I try to use one of the functions that dnstwist.py has. I'm really not sure how I should go about this.

Thanks for your time.

Community
  • 1
  • 1
Shaun Aran
  • 123
  • 4
  • 17

1 Answers1

1

The person you asked about module import, guided you correctly. I also ran the above lines in the interpreter to verify - all of them worked fine:

>>> import dnstwist
>>> fuzz = dnstwist.DomainFuzz("google.com")
>>> fuzz
<dnstwist.DomainFuzz instance at 0xc300e0>
>>> fuzz.generate()
>>> fuzz.domains
[{'domain-name': 'google.com', 'fuzzer': 'Original*'}, {'domain-name': 'googlea.com', 'fuzzer': 'Addition'}, {'domain-name': 'googleb.com', 'fuzzer': 'Addition'}, {'domain-name': 'googlec.com', 'fuzzer': 'Addition'}, {'domain-name': 'googled.com', 'fuzzer': 'Addition'}, {'domain-name': 'googlee.com', 'fuzzer': 'Addition'}, {'domain-name': 'googlef.com', 'fuzzer': 'Addition'}, {'domain-name': 'googleg.com', 'fuzzer': 'Addition'}, 
..................
..................
 'fuzzer': 'Transposition'}, {'domain-name': 'googel.com', 'fuzzer': 'Transposition'}, {'domain-name': 'gaogle.com', 'fuzzer': 'Vowel swap'}, {'domain-name': 'geogle.com', 'fuzzer': 'Vowel swap'}, {'domain-name': 'googlo.com', 'fuzzer': 'Vowel swap'}, {'domain-name': 'googli.com', 'fuzzer': 'Vowel swap'}, {'domain-name': 'guogle.com', 'fuzzer': 'Vowel swap'}, {'domain-name': 'gougle.com', 'fuzzer': 'Vowel swap'}, {'domain-name': 'goegle.com', 'fuzzer': 'Vowel swap'}, {'domain-name': 'goagle.com', 'fuzzer': 'Vowel swap'}, {'domain-name': 'wwgoogle.com', 'fuzzer': 'Various'}, {'domain-name': 'wwwgoogle.com', 'fuzzer': 'Various'}, {'domain-name': 'www-google.com', 'fuzzer': 'Various'}, {'domain-name': 'googlecom.com', 'fuzzer': 'Various'}]
>>> 

Probable reason:

  • Check your directory, you may have more then one dnstwist.py.
  • Also check your copy of dnstwist if it has the class DomainFuzz() code.
Nabeel Ahmed
  • 18,328
  • 4
  • 58
  • 63
  • There is only one `dnstwist.py` in my directory. I took at look at the code itself and it does have the `DomainFuzz()` class within it. This is odd... – Shaun Aran Oct 26 '16 at 14:08
  • I ran all the four lines in the interpreter, all went fine. apart from this import dnstwist, check if by any way you're importing/openning that file – Nabeel Ahmed Oct 26 '16 at 14:10
  • Try importing the class only - from dnstwist import DomainFuzz ; fuzz = DomainFuzz('google.com') – Nabeel Ahmed Oct 26 '16 at 14:13
  • I made a new python file called `import_test.py` where all I did was import dnstwist and call `DomainFuzz()` and it worked perfectly. I don't get it. What do you mean by "check if by any way you're importing/opening that file". Do you mean I might have it open somewhere else? – Shaun Aran Oct 26 '16 at 14:18
  • 1
    I figured out the problem. I had my own function within my code called `dnstwist()`. It must have thought that I was trying to call a function within that function. I renamed it to `do_dnstwist()` and it works perfectly now. – Shaun Aran Oct 26 '16 at 14:22