netarch

Network Archaeology library for Python
git clone https://git.woozle.org/neale/netarch.git

commit
8cd7cb0
parent
c3ced6f
author
Neale Pickett
date
2021-07-02 16:00:22 -0600 MDT
packaged it up
10 files changed,  +216, -8
M .gitignore
+4, -0
1@@ -1 +1,5 @@
2 __pycache__
3+build
4+dist
5+netarch.egg-info
6+*.pyc
R __init__.py => netarch/__init__.py
+2, -3
 1@@ -1,7 +1,6 @@
 2 #! /usr/bin/python3
 3 
 4 import binascii
 5-import sys
 6 import struct
 7 from . import ip
 8 
 9@@ -181,9 +180,9 @@ def _registry(encoding):
10 
11 codecs.register(_registry)
12 
13-def main(session):
14+def main(session, pcaps):
15     s = None
16-    reseq = ip.Dispatch(*sys.argv[1:])
17+    reseq = ip.Dispatch(*pcaps)
18     for _, d in reseq:
19         srv, first, chunk = d
20         if not s:
R crypto.py => netarch/crypto.py
+0, -0
R dumbdecode.py => netarch/dumbdecode.py
+2, -1
 1@@ -1,6 +1,7 @@
 2 #! /usr/bin/python3
 3 
 4 import netarch
 5+import sys
 6 
 7 class DumbPacket(netarch.Packet):
 8 	def parse(self, data):
 9@@ -9,4 +10,4 @@ class DumbPacket(netarch.Packet):
10 class DumbSession(netarch.Session):
11 	Packet = DumbPacket
12 
13-netarch.main(DumbSession)
14+netarch.main(DumbSession, sys.argv[1:])
R hexdump.py => netarch/hexdump.py
+0, -0
R ip.py => netarch/ip.py
+3, -2
 1@@ -12,7 +12,6 @@ import io
 2 try:
 3     import pcap
 4 except ImportError:
 5-    warnings.warn("Using slow pure-python pcap library")
 6     from . import py_pcap as pcap
 7 import os
 8 import cgi
 9@@ -307,7 +306,6 @@ class TCP_Resequence:
10 
11         self.handle = self.handle_handshake
12 
13-
14     def bundle_pending(self, xdi, pkt, seq):
15         """Bundle up any pending packets.
16 
17@@ -366,6 +364,8 @@ class TCP_Resequence:
18 
19         return (xdi, first, gs)
20 
21+    def handle(self, pkt):
22+        """This method will be re-assigned to one of the handle_* methods below"""
23 
24     def handle_handshake(self, pkt):
25         if not self.first:
26@@ -405,6 +405,7 @@ class TCP_Resequence:
27             self.closed = [True, True]
28             self.handle = self.handle_drop
29 
30+            print(self.lastack)
31             return self.bundle_pending(xdi, pkt, self.lastack[idx])
32         else:
33             # Stick it into pending
R py_pcap.py => netarch/py_pcap.py
+3, -2
 1@@ -1,16 +1,17 @@
 2 #! /usr/bin/python3
 3 
 4 import struct
 5-import builtins
 6 
 7 _MAGIC = 0xA1B2C3D4
 8 
 9+builtin_open = open
10+
11 class PcapFile:
12     def __init__(self, stream, mode='r', snaplen=65535, linktype=1):
13         if 'b' not in mode:
14             mode += 'b'
15         try:
16-            self.stream = builtins.open(stream, mode)
17+            self.stream = builtin_open(stream, mode)
18         except TypeError:
19             self.stream = stream
20         try:
R trilobytes.py => netarch/trilobytes.py
+0, -0
R unpack.py => netarch/unpack.py
+0, -0
A setup.py
+202, -0
  1@@ -0,0 +1,202 @@
  2+#! /usr/bin/python3
  3+
  4+"""A setuptools based setup module.
  5+See:
  6+https://packaging.python.org/guides/distributing-packages-using-setuptools/
  7+https://github.com/pypa/sampleproject
  8+"""
  9+
 10+# Always prefer setuptools over distutils
 11+from setuptools import setup, find_packages
 12+import pathlib
 13+
 14+here = pathlib.Path(__file__).parent.resolve()
 15+
 16+# Get the long description from the README file
 17+long_description = (here / 'README.md').read_text(encoding='utf-8')
 18+
 19+# Arguments marked as "Required" below must be included for upload to PyPI.
 20+# Fields marked as "Optional" may be commented out.
 21+
 22+setup(
 23+    # This is the name of your project. The first time you publish this
 24+    # package, this name will be registered for you. It will determine how
 25+    # users can install this project, e.g.:
 26+    #
 27+    # $ pip install sampleproject
 28+    #
 29+    # And where it will live on PyPI: https://pypi.org/project/sampleproject/
 30+    #
 31+    # There are some restrictions on what makes a valid project name
 32+    # specification here:
 33+    # https://packaging.python.org/specifications/core-metadata/#name
 34+    name='netarch',  # Required
 35+
 36+    # Versions should comply with PEP 440:
 37+    # https://www.python.org/dev/peps/pep-0440/
 38+    #
 39+    # For a discussion on single-sourcing the version across setup.py and the
 40+    # project code, see
 41+    # https://packaging.python.org/en/latest/single_source_version.html
 42+    version='1.0.1',  # Required
 43+
 44+    # This is a one-line description or tagline of what your project does. This
 45+    # corresponds to the "Summary" metadata field:
 46+    # https://packaging.python.org/specifications/core-metadata/#summary
 47+    description='Network Archaeology toolkit',  # Optional
 48+
 49+    # This is an optional longer description of your project that represents
 50+    # the body of text which users will see when they visit PyPI.
 51+    #
 52+    # Often, this is the same as your README, so you can just read it in from
 53+    # that file directly (as we have already done above)
 54+    #
 55+    # This field corresponds to the "Description" metadata field:
 56+    # https://packaging.python.org/specifications/core-metadata/#description-optional
 57+    long_description=long_description,  # Optional
 58+
 59+    # Denotes that our long_description is in Markdown; valid values are
 60+    # text/plain, text/x-rst, and text/markdown
 61+    #
 62+    # Optional if long_description is written in reStructuredText (rst) but
 63+    # required for plain-text or Markdown; if unspecified, "applications should
 64+    # attempt to render [the long_description] as text/x-rst; charset=UTF-8 and
 65+    # fall back to text/plain if it is not valid rst" (see link below)
 66+    #
 67+    # This field corresponds to the "Description-Content-Type" metadata field:
 68+    # https://packaging.python.org/specifications/core-metadata/#description-content-type-optional
 69+    long_description_content_type='text/markdown',  # Optional (see note above)
 70+
 71+    # This should be a valid link to your project's main homepage.
 72+    #
 73+    # This field corresponds to the "Home-Page" metadata field:
 74+    # https://packaging.python.org/specifications/core-metadata/#home-page-optional
 75+    url='https://github.com/dirtbags/netarch',  # Optional
 76+
 77+    # This should be your name or the name of the organization which owns the
 78+    # project.
 79+    author='Neale Pickett',  # Optional
 80+
 81+    # This should be a valid email address corresponding to the author listed
 82+    # above.
 83+    author_email='neale@woozle.org',  # Optional
 84+
 85+    # Classifiers help users find your project by categorizing it.
 86+    #
 87+    # For a list of valid classifiers, see https://pypi.org/classifiers/
 88+    classifiers=[  # Optional
 89+        # How mature is this project? Common values are
 90+        #   3 - Alpha
 91+        #   4 - Beta
 92+        #   5 - Production/Stable
 93+        'Development Status :: 5 - Production/Stable',
 94+
 95+        # Indicate who your project is intended for
 96+        'Intended Audience :: Developers',
 97+        #'Topic :: Software Development :: Build Tools',
 98+
 99+        # Pick your license as you wish
100+        'License :: Public Domain',
101+
102+        # Specify the Python versions you support here. In particular, ensure
103+        # that you indicate you support Python 3. These classifiers are *not*
104+        # checked by 'pip install'. See instead 'python_requires' below.
105+        #'Programming Language :: Python :: 3',
106+        #'Programming Language :: Python :: 3.6',
107+        #'Programming Language :: Python :: 3.7',
108+        #'Programming Language :: Python :: 3.8',
109+        #'Programming Language :: Python :: 3.9',
110+        'Programming Language :: Python :: 3 :: Only',
111+    ],
112+
113+    # This field adds keywords for your project which will appear on the
114+    # project page. What does your project relate to?
115+    #
116+    # Note that this is a list of additional keywords, separated
117+    # by commas, to be used to assist searching for the distribution in a
118+    # larger catalog.
119+    keywords='network, packet, tcp, protocol, development',  # Optional
120+
121+    # When your source code is in a subdirectory under the project root, e.g.
122+    # `src/`, it is necessary to specify the `package_dir` argument.
123+    #package_dir={'': 'src'},  # Optional
124+
125+    # You can just specify package directories manually here if your project is
126+    # simple. Or you can use find_packages().
127+    #
128+    # Alternatively, if you just want to distribute a single Python file, use
129+    # the `py_modules` argument instead as follows, which will expect a file
130+    # called `my_module.py` to exist:
131+    #
132+    #   py_modules=["my_module"],
133+    #
134+    #packages=find_packages(where='src'),  # Required
135+    packages=["netarch"],
136+
137+    # Specify which Python versions you support. In contrast to the
138+    # 'Programming Language' classifiers above, 'pip install' will check this
139+    # and refuse to install the project if the version does not match. See
140+    # https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
141+    python_requires='>=3.6, <4',
142+
143+    # This field lists other packages that your project depends on to run.
144+    # Any package you put here will be installed by pip when your project is
145+    # installed, so they must be valid existing projects.
146+    #
147+    # For an analysis of "install_requires" vs pip's requirements files see:
148+    # https://packaging.python.org/en/latest/requirements.html
149+    #install_requires=['peppercorn'],  # Optional
150+
151+    # List additional groups of dependencies here (e.g. development
152+    # dependencies). Users will be able to install these using the "extras"
153+    # syntax, for example:
154+    #
155+    #   $ pip install sampleproject[dev]
156+    #
157+    # Similar to `install_requires` above, these must be valid existing
158+    # projects.
159+    extras_require={  # Optional
160+        #'dev': ['check-manifest'],
161+        #'test': ['coverage'],
162+    },
163+
164+    # If there are data files included in your packages that need to be
165+    # installed, specify them here.
166+    package_data={  # Optional
167+        #'sample': ['package_data.dat'],
168+    },
169+
170+    # Although 'package_data' is the preferred approach, in some case you may
171+    # need to place data files outside of your packages. See:
172+    # http://docs.python.org/distutils/setupscript.html#installing-additional-files
173+    #
174+    # In this case, 'data_file' will be installed into '<sys.prefix>/my_data'
175+    #data_files=[('my_data', ['data/data_file'])],  # Optional
176+
177+    # To provide executable scripts, use entry points in preference to the
178+    # "scripts" keyword. Entry points provide cross-platform support and allow
179+    # `pip` to create the appropriate form of executable for the target
180+    # platform.
181+    #
182+    # For example, the following would provide a command called `sample` which
183+    # executes the function `main` from this package when invoked:
184+    #entry_points={  # Optional
185+        #'console_scripts': [
186+            #'sample=sample:main',
187+        #],
188+    #},
189+
190+    # List additional URLs that are relevant to your project as a dict.
191+    #
192+    # This field corresponds to the "Project-URL" metadata fields:
193+    # https://packaging.python.org/specifications/core-metadata/#project-url-multiple-use
194+    #
195+    # Examples listed include a pattern for specifying where the package tracks
196+    # issues, where the source is hosted, where to say thanks to the package
197+    # maintainers, and where to support the project financially. The key is
198+    # what's used to render the link text on PyPI.
199+    project_urls={  # Optional
200+        'Bug Reports': 'https://github.com/dirtbags/netarch/issues',
201+        'Source': 'https://github.com/dirtbags/netarch/',
202+    },
203+)