Get NS and MX web information python
Question: Im trying to get information about two domain input with this code:

    
    
    #! usr/bin/python
    domainlist=[]
    #Ask for domain 1
    domain = raw_input("------------------------------------------\nIntroduce el primer domino de la pagina web:\n")
    domainlist.append(domain)
    #Ask for domain 2
    domain = raw_input("------------------------------------------\nIntroduce el segundo domino de la pagina web:\n")
    domainlist.append(domain)
    print "-------------------"
    
    #Declare Variable
    #Find dns
    def fundns():
        import dns.resolver
        idns = dns.resolver.query(i,'NS')
        print "Los DNS de %s" % domain + " son:"
        for server in idns:
            print server 
    #Find mx
    def funmx():        
        import dns.resolver
        mx = dns.resolver.query(i,'MX')
        print "Los MX de %s" % domain + " son:"
        for rdata in mx:
            print "Host", rdata.exchange
    for i in domainlist:
        fundns()
        print "----------------------------------------"
        funmx()
    

but I received this error:

> Traceback (most recent call last): File "ejercicio5.py", line 29, in funmx()
> File "ejercicio5.py", line 22, in funmx

I can see in the print all the information unless last `mx` registry, and I
don't know what is wrong...

Some one could help me?


Answer: You need to actually pass the domain names to your functions

    
    
    import dns.resolver
    
    domainlist = ['google.com', 'yahoo.com']
    
    #Declare Variable
    #Find dns
    def fundns(domain):
    
        idns = dns.resolver.query(domain,'NS')
        print "Los DNS de %s" % domain + " son:"
        for server in idns:
            print server 
    #Find mx
    def funmx(domain):        
    
        mx = dns.resolver.query(domain,'MX')
        print "Los MX de %s" % domain + " son:"
        for rdata in mx:
            print "Host", rdata.exchange
    
    for i in domainlist:
        fundns(i)
        print "----------------------------------------"
        funmx(i)
    

Previously you were trying to use global variables, or so it seems.

The Output:

    
    
    Los DNS de google.com son:
    ns3.google.com.
    ns2.google.com.
    ns4.google.com.
    ns1.google.com.
    ----------------------------------------
    Los MX de google.com son:
    Host alt3.aspmx.l.google.com.
    Host alt2.aspmx.l.google.com.
    Host alt4.aspmx.l.google.com.
    Host alt1.aspmx.l.google.com.
    Host aspmx.l.google.com.
    Los DNS de yahoo.com son:
    ns6.yahoo.com.
    ns2.yahoo.com.
    ns5.yahoo.com.
    ns3.yahoo.com.
    ns1.yahoo.com.
    ns4.yahoo.com.
    ----------------------------------------
    Los MX de yahoo.com son:
    Host mta5.am0.yahoodns.net.
    Host mta7.am0.yahoodns.net.
    Host mta6.am0.yahoodns.net.
    

