sniffing-io


Namesniffing-io JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/Shahaf-F-S/sniffing-io
SummaryA simple package for packet sniffing, with static/dynamic filtering options, real-time reaction, I/O operations and more.
upload_time2024-07-20 12:59:19
maintainerNone
docs_urlNone
authorShahaf Frank-Shapir
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Sniffing IO

> A simple package for packet sniffing, with static/dynamic filtering options, real-time reaction, I/O operations and more.

> The sniffing mechanism of sniffing-io is primarily based on the Scapy sniff function, but extends functionality and ease of control.

Installation
-----------
````
pip install sniffing-io
````

example
-----------

````python
from sniffingio import pfv, Sniffer, SniffSettings, write_pcap

ip_filter = pfv(names=['host'], values=['192.168.0.124', '192.168.0.45'])
tcp_filter = pfv(names=['port'], values=[6000])

static_filter = ip_filter & ~tcp_filter

print(static_filter.format())

data = SniffSettings(count=10, static_filter=static_filter)

sniffer = Sniffer(data)
sniffed = sniffer.start()

write_pcap(sniffed, "packets.pcap")
````

Sniffer interface:
````python
from sniffingio import Sniffer, SniffSettings, PacketList

sniffer = Sniffer(SniffSettings(...))

sniffed1: PacketList = sniffer.start()

sniffer.thread_start()
sniffer.stop()

sniffed2: PacketList = sniffer.packets()
````

PacketFilter interface:

intersection:
````python
from sniffingio import PacketFilterIntersection, pfv

pf1 = pfv(names=['host'], values=['192.168.0.124', '192.168.0.45'])
pf2 = pfv(names=['port'], values=[6000])

intersection1 = PacketFilterIntersection((pf1, pf2))
intersection2 = pf1 & pf2

print("same operation:", intersection1 == intersection2)
print("BPF:", intersection2.format())
````

output:
```
same operation: True
BPF: (((tcp or udp)) and ((src port 6000)))
```

union:
````python
from sniffingio import PacketFilterUnion, pfv

pf1 = pfv(names=['host'], values=['192.168.0.124', '192.168.0.45'])
pf2 = pfv(names=['port'], values=[6000])

union1 = PacketFilterUnion((pf1, pf2))
union2 = pf1 | pf2

print("same operation:", union1 == union2)
print("BPF:", union2.format())
````

output:
```
same operation: True
BPF: (((tcp or udp)) or ((src port 6000)))
```

negation:
````python
from sniffingio import PacketFilterNegation, pfv

pf = pfv(values=["tcp", "udp"])

negation1 = PacketFilterNegation(pf)
negation2 = ~pf

print("same operation:", negation1 == negation2)
print("BPF:", negation2.format())
````

output:
```
same operation: True
BPF: (not ((tcp or udp)))
```

simple PacketFilter I/O:
````python
from sniffingio import pfv, load_filters

ip_filter = pfv(names=['host'], values=['192.168.0.124', '192.168.0.45'])
tcp_filter = pfv(names=['port'], values=[6000])

org_pf = ip_filter & ~tcp_filter

org_pf_dump = org_pf.dump()
loaded_pf = load_filters(org_pf_dump)

print(org_pf_dump)
print(loaded_pf.format())
print('equal objects:', org_pf == loaded_pf)
````

output:
```
{'filters': ({'types': None, 'names': ['host'], 'values': ['192.168.0.124', '192.168.0.45'], 'source_values': None, 'destination_values': None, 'attributes': None, 'type': 'values'}, {'filter': {'types': None, 'names': ['port'], 'values': [6000], 'source_values': None, 'destination_values': None, 'attributes': None, 'type': 'values'}, 'type': 'negation'}), 'type': 'intersection'}
(((host 192.168.0.124) or (host 192.168.0.45)) and (not (port 6000)))
equal objects: True
```

SniffSettings options:

````python
count: int = 0
timeout: int = None
store: bool = True
quiet: bool = True
callback: PacketCallback = None
printer: bool | PacketCallback = None
live_filter: LivePacketFilter = None
stop_filter: LivePacketFilter = None
interface: str | NetworkInterface = None
static_filter: str | BasePacketFilter = None
start_callback: Callable[[], ...] = None
````

PacketFilter options:
````python
protocols: list[str] = None
source_hosts: list[str] = None
source_ports: list[int] = None
destination_hosts: list[str] = None
destination_ports: list[int] = None
````

Scapy Packet/PacketList I/O operations:
````python
from sniffingio import PacketList, load_packet, dump_packet, write_pcap, read_pcap

org_p: PacketList = ...

org_p_dump: bytes = dump_packet(org_p)
loaded_p: PacketList = load_packet(org_p_dump)

print("equal data:", org_p_dump == dump_packet(loaded_p))

write_pcap(org_p, "packets.pcap")
read_p = read_pcap("packets.pcap")

print("equal data:", org_p_dump == dump_packet(read_p))
````

output:
```
equal data: True
equal data: True
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Shahaf-F-S/sniffing-io",
    "name": "sniffing-io",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Shahaf Frank-Shapir",
    "author_email": "shahaffrs@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/90/84/2039588dc6b6cb4042cc9468657ab1d6553800cc30114456ba80a3f88b11/sniffing_io-0.3.2.tar.gz",
    "platform": null,
    "description": "# Sniffing IO\r\n\r\n> A simple package for packet sniffing, with static/dynamic filtering options, real-time reaction, I/O operations and more.\r\n\r\n> The sniffing mechanism of sniffing-io is primarily based on the Scapy sniff function, but extends functionality and ease of control.\r\n\r\nInstallation\r\n-----------\r\n````\r\npip install sniffing-io\r\n````\r\n\r\nexample\r\n-----------\r\n\r\n````python\r\nfrom sniffingio import pfv, Sniffer, SniffSettings, write_pcap\r\n\r\nip_filter = pfv(names=['host'], values=['192.168.0.124', '192.168.0.45'])\r\ntcp_filter = pfv(names=['port'], values=[6000])\r\n\r\nstatic_filter = ip_filter & ~tcp_filter\r\n\r\nprint(static_filter.format())\r\n\r\ndata = SniffSettings(count=10, static_filter=static_filter)\r\n\r\nsniffer = Sniffer(data)\r\nsniffed = sniffer.start()\r\n\r\nwrite_pcap(sniffed, \"packets.pcap\")\r\n````\r\n\r\nSniffer interface:\r\n````python\r\nfrom sniffingio import Sniffer, SniffSettings, PacketList\r\n\r\nsniffer = Sniffer(SniffSettings(...))\r\n\r\nsniffed1: PacketList = sniffer.start()\r\n\r\nsniffer.thread_start()\r\nsniffer.stop()\r\n\r\nsniffed2: PacketList = sniffer.packets()\r\n````\r\n\r\nPacketFilter interface:\r\n\r\nintersection:\r\n````python\r\nfrom sniffingio import PacketFilterIntersection, pfv\r\n\r\npf1 = pfv(names=['host'], values=['192.168.0.124', '192.168.0.45'])\r\npf2 = pfv(names=['port'], values=[6000])\r\n\r\nintersection1 = PacketFilterIntersection((pf1, pf2))\r\nintersection2 = pf1 & pf2\r\n\r\nprint(\"same operation:\", intersection1 == intersection2)\r\nprint(\"BPF:\", intersection2.format())\r\n````\r\n\r\noutput:\r\n```\r\nsame operation: True\r\nBPF: (((tcp or udp)) and ((src port 6000)))\r\n```\r\n\r\nunion:\r\n````python\r\nfrom sniffingio import PacketFilterUnion, pfv\r\n\r\npf1 = pfv(names=['host'], values=['192.168.0.124', '192.168.0.45'])\r\npf2 = pfv(names=['port'], values=[6000])\r\n\r\nunion1 = PacketFilterUnion((pf1, pf2))\r\nunion2 = pf1 | pf2\r\n\r\nprint(\"same operation:\", union1 == union2)\r\nprint(\"BPF:\", union2.format())\r\n````\r\n\r\noutput:\r\n```\r\nsame operation: True\r\nBPF: (((tcp or udp)) or ((src port 6000)))\r\n```\r\n\r\nnegation:\r\n````python\r\nfrom sniffingio import PacketFilterNegation, pfv\r\n\r\npf = pfv(values=[\"tcp\", \"udp\"])\r\n\r\nnegation1 = PacketFilterNegation(pf)\r\nnegation2 = ~pf\r\n\r\nprint(\"same operation:\", negation1 == negation2)\r\nprint(\"BPF:\", negation2.format())\r\n````\r\n\r\noutput:\r\n```\r\nsame operation: True\r\nBPF: (not ((tcp or udp)))\r\n```\r\n\r\nsimple PacketFilter I/O:\r\n````python\r\nfrom sniffingio import pfv, load_filters\r\n\r\nip_filter = pfv(names=['host'], values=['192.168.0.124', '192.168.0.45'])\r\ntcp_filter = pfv(names=['port'], values=[6000])\r\n\r\norg_pf = ip_filter & ~tcp_filter\r\n\r\norg_pf_dump = org_pf.dump()\r\nloaded_pf = load_filters(org_pf_dump)\r\n\r\nprint(org_pf_dump)\r\nprint(loaded_pf.format())\r\nprint('equal objects:', org_pf == loaded_pf)\r\n````\r\n\r\noutput:\r\n```\r\n{'filters': ({'types': None, 'names': ['host'], 'values': ['192.168.0.124', '192.168.0.45'], 'source_values': None, 'destination_values': None, 'attributes': None, 'type': 'values'}, {'filter': {'types': None, 'names': ['port'], 'values': [6000], 'source_values': None, 'destination_values': None, 'attributes': None, 'type': 'values'}, 'type': 'negation'}), 'type': 'intersection'}\r\n(((host 192.168.0.124) or (host 192.168.0.45)) and (not (port 6000)))\r\nequal objects: True\r\n```\r\n\r\nSniffSettings options:\r\n\r\n````python\r\ncount: int = 0\r\ntimeout: int = None\r\nstore: bool = True\r\nquiet: bool = True\r\ncallback: PacketCallback = None\r\nprinter: bool | PacketCallback = None\r\nlive_filter: LivePacketFilter = None\r\nstop_filter: LivePacketFilter = None\r\ninterface: str | NetworkInterface = None\r\nstatic_filter: str | BasePacketFilter = None\r\nstart_callback: Callable[[], ...] = None\r\n````\r\n\r\nPacketFilter options:\r\n````python\r\nprotocols: list[str] = None\r\nsource_hosts: list[str] = None\r\nsource_ports: list[int] = None\r\ndestination_hosts: list[str] = None\r\ndestination_ports: list[int] = None\r\n````\r\n\r\nScapy Packet/PacketList I/O operations:\r\n````python\r\nfrom sniffingio import PacketList, load_packet, dump_packet, write_pcap, read_pcap\r\n\r\norg_p: PacketList = ...\r\n\r\norg_p_dump: bytes = dump_packet(org_p)\r\nloaded_p: PacketList = load_packet(org_p_dump)\r\n\r\nprint(\"equal data:\", org_p_dump == dump_packet(loaded_p))\r\n\r\nwrite_pcap(org_p, \"packets.pcap\")\r\nread_p = read_pcap(\"packets.pcap\")\r\n\r\nprint(\"equal data:\", org_p_dump == dump_packet(read_p))\r\n````\r\n\r\noutput:\r\n```\r\nequal data: True\r\nequal data: True\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple package for packet sniffing, with static/dynamic filtering options, real-time reaction, I/O operations and more.",
    "version": "0.3.2",
    "project_urls": {
        "Homepage": "https://github.com/Shahaf-F-S/sniffing-io"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90842039588dc6b6cb4042cc9468657ab1d6553800cc30114456ba80a3f88b11",
                "md5": "575f56a8150161d16fc49c6091683f58",
                "sha256": "ca73d0ad3ea4441ef1096c87fab88dc850a36437ee61dc87a819737f6ff9ad14"
            },
            "downloads": -1,
            "filename": "sniffing_io-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "575f56a8150161d16fc49c6091683f58",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 11338,
            "upload_time": "2024-07-20T12:59:19",
            "upload_time_iso_8601": "2024-07-20T12:59:19.815986Z",
            "url": "https://files.pythonhosted.org/packages/90/84/2039588dc6b6cb4042cc9468657ab1d6553800cc30114456ba80a3f88b11/sniffing_io-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-20 12:59:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Shahaf-F-S",
    "github_project": "sniffing-io",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "sniffing-io"
}
        
Elapsed time: 0.47874s