the socket is not recieving the port number and address in below code I don't know why

时间:2019-05-31 11:22:59

标签: python-3.x sockets dns

I am trying to get the data from the socket but it seems the socket is not recieving any data. Is there a problem I dont understand why it is not receiving port number and address

def startMyDNS():
    sock = socket(AF_INET, SOCK_DGRAM)
    sock.bind(('0.0.0.0', 55553))
    print "STARTING DNS\n"

    while secret_Received !=1:
        bytesReq , addr = sock.recvfrom(1024)
        sPort = addr[1]
        dnsReq = DNS(bytesReq)
        qId = dnsReq.id

        assert dnsqtypes[dnsReq[DNSQR].qtype]=='A', dnsReq[DNSQR].qtype
        query = dnsReq[DNSQR].qname.decode('ascii')
        if query[-1] == '.': #check if last character of domain requested is a dot
            query = query[:-1]
        assert query == myDomain
        #create an authoritative DNSResp for "badguy.ru"
        dnsResp = DNS(id = dnsReq.id, ancount=1, qr=1, rd=0, aa=1, an = DNSRR(rrname=myDomain, type='A', rdata=fakeBank_Ip, ttl=3600) )
        #send the response
        sock.sendto(bytes(dnsResp), addr)
        #write source port and query Id
        with open(filename, 'w') as f:
            f.write(str(sPort)+','+str(qId))

0 个答案:

没有答案