|
82 | 82 | ],
|
83 | 83 | "source": [
|
84 | 84 | "ans = sr([IP(dst=\"8.8.8.8\", ttl=(1, 8), options=IPOption_RR())/ICMP(seq=RandShort()), IP(dst=\"8.8.8.8\", ttl=(1, 8), options=IPOption_Traceroute())/ICMP(seq=RandShort()), IP(dst=\"8.8.8.8\", ttl=(1, 8))/ICMP(seq=RandShort())], verbose=False, timeout=3)[0]\n",
|
85 |
| - "ans.make_table(lambda (x, y): (\", \".join(z.summary() for z in x[IP].options) or '-', x[IP].ttl, y.sprintf(\"%IP.src% %ICMP.type%\")))" |
| 85 | + "ans.make_table(lambda x_y: (\", \".join(z.summary() for z in x_y[0][IP].options) or '-', x_y[0][IP].ttl, x_y[1].sprintf(\"%IP.src% %ICMP.type%\")))" |
86 | 86 | ]
|
87 | 87 | },
|
88 | 88 | {
|
|
259 | 259 | }
|
260 | 260 | ],
|
261 | 261 | "source": [
|
262 |
| - "print p.dst # first layer that has an src field, here Ether\n", |
263 |
| - "print p[IP].src # explicitly access the src field of the IP layer\n", |
| 262 | + "print(p.dst) # first layer that has an src field, here Ether\n", |
| 263 | + "print(p[IP].src) # explicitly access the src field of the IP layer\n", |
264 | 264 | "\n",
|
265 | 265 | "# sprintf() is a useful method to display fields\n",
|
266 |
| - "print p.sprintf(\"%Ether.src% > %Ether.dst%\\n%IP.src% > %IP.dst%\")" |
| 266 | + "print(p.sprintf(\"%Ether.src% > %Ether.dst%\\n%IP.src% > %IP.dst%\"))" |
267 | 267 | ]
|
268 | 268 | },
|
269 | 269 | {
|
|
287 | 287 | }
|
288 | 288 | ],
|
289 | 289 | "source": [
|
290 |
| - "print p.sprintf(\"%TCP.flags% %TCP.dport%\")" |
| 290 | + "print(p.sprintf(\"%TCP.flags% %TCP.dport%\"))" |
291 | 291 | ]
|
292 | 292 | },
|
293 | 293 | {
|
|
444 | 444 | ],
|
445 | 445 | "source": [
|
446 | 446 | "# Access the first tuple\n",
|
447 |
| - "print r[0][0].summary() # the packet sent\n", |
448 |
| - "print r[0][1].summary() # the answer received\n", |
| 447 | + "print(r[0][0].summary()) # the packet sent\n", |
| 448 | + "print(r[0][1].summary()) # the answer received\n", |
449 | 449 | "\n",
|
450 | 450 | "# Access the ICMP layer. Scapy received a time-exceeded error message\n",
|
451 | 451 | "r[0][1][ICMP]"
|
|
658 | 658 | ],
|
659 | 659 | "source": [
|
660 | 660 | "%matplotlib inline\n",
|
661 |
| - "ans.multiplot(lambda (x, y): (y[IP].src, (y.time, y[IP].id)), plot_xy=True)" |
| 661 | + "ans.multiplot(lambda x_y: (x_y[1][IP].src, (x_y[1].time, x_y[1][IP].id)), plot_xy=True)" |
662 | 662 | ]
|
663 | 663 | },
|
664 | 664 | {
|
|
683 | 683 | ],
|
684 | 684 | "source": [
|
685 | 685 | "pkt = IP() / UDP() / DNS(qd=DNSQR())\n",
|
686 |
| - "print repr(raw(pkt))" |
| 686 | + "print(repr(raw(pkt)))" |
687 | 687 | ]
|
688 | 688 | },
|
689 | 689 | {
|
|
708 | 708 | }
|
709 | 709 | ],
|
710 | 710 | "source": [
|
711 |
| - "print pkt.summary()" |
| 711 | + "print(pkt.summary())" |
712 | 712 | ]
|
713 | 713 | },
|
714 | 714 | {
|
|
944 | 944 | "source": [
|
945 | 945 | "ans = sr(IP(dst=[\"scanme.nmap.org\", \"nmap.org\"])/TCP(dport=[22, 80, 443, 31337]), timeout=3, verbose=False)[0]\n",
|
946 | 946 | "ans.extend(sr(IP(dst=[\"scanme.nmap.org\", \"nmap.org\"])/UDP(dport=53)/DNS(qd=DNSQR()), timeout=3, verbose=False)[0])\n",
|
947 |
| - "ans.make_table(lambda (x, y): (x[IP].dst, x.sprintf('%IP.proto%/{TCP:%r,TCP.dport%}{UDP:%r,UDP.dport%}'), y.sprintf('{TCP:%TCP.flags%}{ICMP:%ICMP.type%}')))" |
| 947 | + "ans.make_table(lambda x_y: (x_y[0][IP].dst, x_y[0].sprintf('%IP.proto%/{TCP:%r,TCP.dport%}{UDP:%r,UDP.dport%}'), x_y[1].sprintf('{TCP:%TCP.flags%}{ICMP:%ICMP.type%}')))" |
948 | 948 | ]
|
949 | 949 | },
|
950 | 950 | {
|
|
1082 | 1082 | " parser.add_argument(\"ipv6_address\", help=\"An IPv6 address\")\n",
|
1083 | 1083 | " args = parser.parse_args()\n",
|
1084 | 1084 | "\n",
|
1085 |
| - " print sr1(IPv6(dst=args.ipv6_address)/ICMPv6EchoRequest(), verbose=0).summary()" |
| 1085 | + " print(sr1(IPv6(dst=args.ipv6_address)/ICMPv6EchoRequest(), verbose=0).summary())" |
1086 | 1086 | ]
|
1087 | 1087 | },
|
1088 | 1088 | {
|
|
1244 | 1244 | "\n",
|
1245 | 1245 | " @ATMT.state()\n",
|
1246 | 1246 | " def SYN(self):\n",
|
1247 |
| - " print \"-> SYN\"\n", |
| 1247 | + " print(\"-> SYN\")\n", |
1248 | 1248 | "\n",
|
1249 | 1249 | " @ATMT.state()\n",
|
1250 | 1250 | " def SYN_ACK(self):\n",
|
1251 |
| - " print \"<- SYN/ACK\"\n", |
| 1251 | + " print(\"<- SYN/ACK\")\n", |
1252 | 1252 | " raise self.END()\n",
|
1253 | 1253 | "\n",
|
1254 | 1254 | " @ATMT.state()\n",
|
1255 | 1255 | " def RST(self):\n",
|
1256 |
| - " print \"<- RST\"\n", |
| 1256 | + " print(\"<- RST\")\n", |
1257 | 1257 | " raise self.END()\n",
|
1258 | 1258 | "\n",
|
1259 | 1259 | " @ATMT.state()\n",
|
1260 | 1260 | " def ERROR(self):\n",
|
1261 |
| - " print \"!! ERROR\"\n", |
| 1261 | + " print(\"!! ERROR\")\n", |
1262 | 1262 | " raise self.END()\n",
|
1263 | 1263 | " @ATMT.state(final=1)\n",
|
1264 | 1264 | " def END(self):\n",
|
|
0 commit comments