Question

In: Computer Science

When using scapy in python how can I get the same result as the snippit bellow?...

When using scapy in python how can I get the same result as the snippit bellow? (which in run in terminal)
>>> sr(IP(dst="192.168.8.1")/TCP(dport=[21,22,23]))
Received 6 packets, got 3 answers, remaining 0 packets
(<Results: UDP:0 TCP:3 ICMP:0 Other:0>, <Unanswered: UDP:0 TCP:0 ICMP:0 Other:0>)
>>> ans,unans=_
>>> ans.summary()
IP / TCP 192.168.8.14:20 > 192.168.8.1:21 S ==> Ether / IP / TCP 192.168.8.1:21 > 192.168.8.14:20 RA / Padding
IP / TCP 192.168.8.14:20 > 192.168.8.1:22 S ==> Ether / IP / TCP 192.168.8.1:22 > 192.168.8.14:20 RA / Padding
IP / TCP 192.168.8.14:20 > 192.168.8.1:23 S ==> Ether / IP / TCP 192.168.8.1:23 > 192.168.8.14:20 RA / Padding

I tried doing something like res = sr(IP(dst="192.168.8.1")/TCP(dport=[21,22,23])) and then doing res.summary(), but it doesnt seem to work :(

Solutions

Expert Solution

Scapy is a library made in Python, with its own CLI which allows to create, modify, send and capture network packets.

It can be used interactively through the command line interface or as a library by importing it into Python programs. It can also run on Linux, Mac OS X and Windows systems

First, we play a bit and create 4 IP packets at once

Fields can be made human readable. For example IP and TCP flags

>>> sr(IP(dst="192.168.8.1")/TCP(dport=[21,22,23]))
(<Results: UDP:0 TCP:3 ICMP:0 Other:0>, <Unanswered: UDP:0 TCP:0 ICMP:0 Other:0>)
>>> ans,unans=_
>>> ans.summary()
IP / TCP 192.168.8.14:20 > 192.168.8.1:21 S ==> Ether / IP / TCP 192.168.8.1:21 > 192.168.8.14:20 RA / Padding
IP / TCP 192.168.8.14:20 > 192.168.8.1:22 S ==> Ether / IP / TCP 192.168.8.1:22 > 192.168.8.14:20 RA / Padding
IP / TCP 192.168.8.14:20 > 192.168.8.1:23 S ==> Ether / IP / TCP 192.168.8.1:23 > 192.168.8.14:20 RA / Padding

Scapy has a powerful TCP traceroute function

>>> send(IP(dst='8.8.8.8')/TCP(dport=53, flags='S')) .

Sent 1 packets.

>>> >>> send(IP(dst=['8.8.8.8', '8.8.8.4'])/TCP(dport=53, flags='S')) .. Sent 2 packets.

>>> >>> send(IP(dst='8.8.8.8')/TCP(dport=53, flags='S'), count=10) .......... Sent 10 packets.

>>> >>> send(IP(dst='8.8.8.8')/TCP(dport=53, flags='S'), loop=1) ......................... [... snipped ...] Sent 1503 packets.

The loopback interface is a very special. Packets going through it are not really assembled and dissassembled.


Related Solutions

"How can I connect to Hadoop Hive using Python? I've tried using PyHive but always get...
"How can I connect to Hadoop Hive using Python? I've tried using PyHive but always get the error: ...could not start SASL... no mechanism available: unable to find a callback: 2"
I have the following python code. I get the following message when running it using a...
I have the following python code. I get the following message when running it using a test script which I cannot send here: while textstring[iterator].isspace(): # loop until we get other than space character IndexError: string index out of range. Please find out why and correct the code. def createWords(textstrings): createdWords = [] # empty list for textstring in textstrings: # iterate through each string in trxtstrings iterator = 0 begin = iterator # new begin variable while (iterator <...
How can I get ATP and NADPH from DHAP using glycolysis and PPP?
How can I get ATP and NADPH from DHAP using glycolysis and PPP?
Writing python code: Can you do for me this. The question looks bellow Overview : As...
Writing python code: Can you do for me this. The question looks bellow Overview : As a programmer, you have be asked by a good friend to create a program that will allow them to keep track of their personal expenses. They want to be able to enter their expenses for the month, store them in a file, and then have the ability to retrieve them later. However, your friend only wants certain people to have the ability to view...
How can different genotypes result in the same phenotype? Give two examples using genotypes. Type all...
How can different genotypes result in the same phenotype? Give two examples using genotypes. Type all genotypes in the proper notation, e.g., Xw+, by using the Microsoft superscript function
How can I get density of state, Fermi energy, and total energy in 1,2 dimension when...
How can I get density of state, Fermi energy, and total energy in 1,2 dimension when we have N electrons without interaction.
Hi, I need to finish function purser,which will include header row and i can get same...
Hi, I need to finish function purser,which will include header row and i can get same output /* [ { firstName: 'moe', lastName: 'green' }, { firstName: 'lucy', lastName: 'liu' }, { firstName: 'ethyl', lastName: 'mertz' } ]*/ In javascript please const parser=(d)=>{ let arr=[]; let newArr=[]; let obj={} let items=d.split('|'); for (let i=0;i<items.length;i++){ arr[i]=items[i].split(','); } for (let z=0;z<arr.length;z++){ newArr=newArr.concat(arr[z]); } for(var y = 0;y < newArr.length;y+=2){ obj[newArr[y]]= newArr[y+1]; } //const res = newArr.reduce((a,b)=> (a[b]='',a),{}); return obj; } const data...
If i were to get the amount of heat transfer using constant pressure calorimetery, can I...
If i were to get the amount of heat transfer using constant pressure calorimetery, can I get the amount for the constant volume calorimetery using that value? Or vice versa?
Multiply the following base 10 numbers together and then show how the same result can be...
Multiply the following base 10 numbers together and then show how the same result can be obtained via the DFT (fft). Explain your method. 823415 multiplied by 234671
I know the what the answers are but I don't know how to get them. Can...
I know the what the answers are but I don't know how to get them. Can you please explain the process? Thank you. Part VII. Discontinued Operations and Earnings per Share (11 points) Todd Corporation had pre-tax income for 2017 of $2,500,000. On December 31, 2017, Boyd disposed of a component of its business that represented a strategic shift in operation. That component had a Loss on Discontinued Operations of $450,000 (pre-tax). Boyd received $1,000,000 net cash proceeds from the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT