Several features that should help you use Scapy
Project description
Scapy helper
Several features that should help you use Scapy.
TL;DR
from scapy.layers.inet import Ether
from scapy_helper import *
# Dump frame hex
hex_value = get_hex(Ether())
# hex_value:
'ff ff ff ff ff ff 00 00 00 00 00 00 90 00'
# Convert and print
show_hex(Ether())
# output:
# ff ff ff ff ff ff 00 00 00 00 00 00 90 00
# Show the differences
# can be result of get_hex() or string or frame
second_ether = "ff ff fc ff ff fa 00 00 00 00 00 00 90 00 11 11 00 22"
show_diff(Ether(), second_ether)
# output:
# WARN:: Frame len is not the same
# WARN:: Second row is longer by the 4B
#
# __ __ ff __ __ ff __ 00 00 00 00 00 __ __ XX XX XX XX | len: 14B
# __ __ fc __ __ fa __ 11 11 11 11 11 __ __ 11 11 00 22 | len: 18B
#
# Not equal at 11B
# You can add a index to it
show_diff(Ether(), second_ether, index=True)
# output:
# __ __ ff __ __ ff __ 00 00 00 00 00 __ __ XX XX XX XX | len: 14B
# __ __ fc __ __ fa __ 11 11 11 11 11 __ __ 11 11 00 22 | len: 18B
# |
# ^2 ^5 ^7 ^8 ^9 10 11 14 15 16 17 | position
#
# Not equal at 11B
# You can add a custom char to mark a missing elements
show_diff(Ether(), second_ether, index=True, empty_char="+")
# output:
# __ __ ff __ __ ff __ 00 00 00 00 00 __ __ ++ ++ ++ ++ | len: 14B
# __ __ fc __ __ fa __ 11 11 11 11 11 __ __ 11 11 00 22 | len: 18B
# |
# ^2 ^5 ^7 ^8 ^9 10 11 14 15 16 17 | position
Test case usage
Extends test class using PacketAssert (since v0.3.1)
Note: In the v0.3.0 this class was called HexEqual
You can use assertHexEqual/assertHexNotEqual and assertBytesEqual/assertBytesNotEqual in the tests. When the assertion fails, wrapper produces information about the frames (in hex).
import unittest
from scapy_helper.test_case_extensions.packet_assert import PacketAssert
class TestExample(unittest.TestCase, PacketAssert):
def test_example(self):
self.assertHexEqual(Ether(), Ether("10.10.10.10"), "Frame should be the same")
def text_example_negative(self):
self.assertNotEqual(Ether(), Ether(), "Frame should be diffrent")
def test_example_bytes(self):
self.assertBytesEqaul(Ether(), Ether(), "Bytes should be equal")
hex_equal (since v0.1.11)
Return bool status of equality and print status if there is a difference between objects
from scapy_helper import hex_equal
# hex_equal(first, second, show_inequalities=True, **options_for_show_diff):
assert hex_equal(Ether(), second_ether)
Compare
table_diff (tdiff as shortcut)
from scapy_helper.compare import Compare
Compare(frame_1, frame_2).table_diff()
| Diff or header | Element | First | Second |
|-----------------------------|-----------|-------------------|-------------------|
| ###[ Ethernet ]### | | | |
| | dst | 00:00:00:00:00:00 | 00:00:00:00:00:00 |
| | src | 00:00:00:00:00:00 | 00:00:00:00:00:00 |
| | type | IPv4 | IPv4 |
| ###[ IP ]### | | | |
| | version | 4 | 4 |
| | ihl | None | None |
| | tos | 0x0 | 0x0 |
| | len | None | None |
| | id | 1 | 1 |
| | flags | | |
| | frag | 0 | 0 |
| 15 != 20 | ttl | 15 | 20 |
| | proto | udp | udp |
| | chksum | None | None |
| 192.168.1.1 != 192.168.1.2 | src | 192.168.1.1 | 192.168.1.2 |
| | dst | 192.168.1.20 | 192.168.1.20 |
| \options \ | | | |
| ###[ UDP ]### | | | |
| | sport | domain | domain |
| | dport | domain | domain |
| | len | None | None |
| | chksum | None | None |
| | | | |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scapy_helper-0.3.3.tar.gz.
File metadata
- Download URL: scapy_helper-0.3.3.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
662f28620c98ea6c8930a298e45e88c043faac30b07aebf14afd7962bdc536ad
|
|
| MD5 |
26ee43a3495bfd02544eb1d7fe3b0692
|
|
| BLAKE2b-256 |
2b0a07a5f19e0374c65012dfac4b27cd0b43efe393a7366cfacfd831493a1a07
|
File details
Details for the file scapy_helper-0.3.3-py3-none-any.whl.
File metadata
- Download URL: scapy_helper-0.3.3-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f87e532a50c1bdb80d5f578686376bcf992a857a980f4948996cdc82b6aa0a7
|
|
| MD5 |
b722ceaf289ec4e3eef0b2da206bbe63
|
|
| BLAKE2b-256 |
60265a83e22dfa9171a2b090dfbfad963c821c7af337fedf3f48da3a5e212c73
|