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 <...
Can I get this logic in Python? plus what software I can use it to run?...
Can I get this logic in Python? plus what software I can use it to run? thanks and will rate!!! Search Lab implement the following logic in Python, use appropriate data types. Data types are represented as either numeric (num) or string. string name string address num item num quantity num price num SIZE = 6 num VALID_ITEM [SIZE] = 106, 108, 307, 405, 457, 688 num VALID_ITEM_PRICE [SIZE] = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00 num sub string foundIt...
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?
Write a Python program that extracts 1000 unique links from Twitter using Tweepy. How can I...
Write a Python program that extracts 1000 unique links from Twitter using Tweepy. How can I filter out all links with Twitter domains and shortened links?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT