Skip to content
This repository was archived by the owner on Apr 13, 2022. It is now read-only.

Commit 416570e

Browse files
committed
Initial commit
0 parents  commit 416570e

26 files changed

Lines changed: 2119 additions & 0 deletions

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Archive/
2+
__pycache__/
3+
venv/
4+
*.csv
5+
*.csv#
6+
*.ods
7+
*.ods#
8+
*.pcap
9+
*.pyc
10+
.idea

.gitlab-ci.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
image: python:3.7
2+
3+
stages:
4+
- test
5+
- build
6+
- release
7+
- integration test
8+
- deploy
9+
10+
variables:
11+
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
12+
13+
before_script:
14+
- pip install -U pip
15+
- pip install virtualenv
16+
- virtualenv venv
17+
- source venv/bin/activate
18+
- pip install tox twine
19+
20+
cache:
21+
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
22+
paths:
23+
- .cache/
24+
- .tox/
25+
- venv/
26+
27+
linter:
28+
stage: test
29+
allow_failure: true
30+
script:
31+
- tox -e linter
32+
33+
test:
34+
stage: test
35+
script:
36+
- tox -e py37
37+
artifacts:
38+
when: always
39+
reports:
40+
junit: report.xml
41+
42+
build:
43+
stage: build
44+
script:
45+
- make build
46+
- tox -e pypi
47+
- make install
48+
- cicflowmeter -h
49+
needs: [test]
50+
artifacts:
51+
paths:
52+
- dist/
53+
54+
release:
55+
stage: release
56+
script:
57+
- twine upload dist/* -u "__token__" -p $TWINE_TOKEN
58+
when: manual
59+
artifacts:
60+
paths:
61+
- dist
62+
only:
63+
- tags
64+
# integrate:
65+
# stage: integration test
66+
# script: echo test
67+
# needs:
68+
# - linter
69+
# - test
70+
# - build
71+
72+
# deploy_staging:
73+
# stage: deploy
74+
# script: echo "Deploy here"
75+
# environment:
76+
# name: staging
77+
# url: https://beta.example.com
78+
# needs: [integrate]
79+
80+
# deploy_production:
81+
# stage: deploy
82+
# script: echo "Deploy here"
83+
# environment:
84+
# name: production
85+
# url: https://example.com
86+
# when: manual
87+
# needs: [integrate]
88+
# only:
89+
# - master
90+
91+
# notification:
92+
# stage: .post
93+
# script:
94+
# - curl -X POST $ZULIP_URL -u $ZULIP_EMAIL:$ZULIP_API -d "type=private" -d "to=$ZULIP_EMAIL" -d "content=$CI_COMMIT_DESCRIPTION - passed the tests."
95+
# needs: [integrate]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Hieu Le
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
VERSION:=$(shell python setup.py --version)
2+
3+
install:
4+
python setup.py install
5+
6+
uninstall:
7+
pip uninstall cicflowmeter -y
8+
9+
clean:
10+
rm -rf *.egg-info build dist report.xml
11+
12+
build:
13+
python setup.py sdist bdist_wheel --universal
14+
15+
release:
16+
@git tag -a v$(VERSION)
17+
@git push --tag

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Python CICFlowMeter
2+
3+
> This project is not maintained actively by me. If you found something wrong (bugs, incorrect results) feel free to create merge request.
4+
5+
### Installation
6+
7+
```sh
8+
git clone https://gitlab.com/hieulw/cicflowmeter
9+
cd cicflowmeter
10+
python setup.py install
11+
```
12+
13+
### Usage
14+
15+
```sh
16+
usage: cicflowmeter [-h] (-i INPUT_INTERFACE | -f INPUT_FILE) [-c] [-u URL_MODEL] output
17+
18+
positional arguments:
19+
output output file name (in flow mode) or directory (in sequence mode)
20+
21+
optional arguments:
22+
-h, --help show this help message and exit
23+
-i INPUT_INTERFACE capture online data from INPUT_INTERFACE
24+
-f INPUT_FILE capture offline data from INPUT_FILE
25+
-c, --csv, --flow output flows as csv
26+
```
27+
28+
Convert pcap file to flow csv:
29+
30+
```
31+
cicflowmeter -f example.pcap -c flows.csv
32+
```
33+
34+
Sniff packets real-time from interface to flow csv: (**need root permission**)
35+
36+
```
37+
cicflowmeter -i eth0 -c flows.csv
38+
```
39+
40+
### Reference: https://www.unb.ca/cic/research/applications.html#CICFlowMeter

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
numpy==1.18
2+
scipy==1.4.1
3+
scapy==2.4.3
4+
requests

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
max-line-length = 110
3+
4+
[black]
5+
line-length=100

setup.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import io
4+
import os
5+
6+
from setuptools import find_packages, setup
7+
8+
# Package meta-data.
9+
NAME = "cicflowmeter"
10+
DESCRIPTION = "CICFlowMeter V3 Python Implementation"
11+
URL = "https://gitlab.com/hieulw/cicflowmeter"
12+
13+
AUTHOR = "Le Hieu"
14+
REQUIRES_PYTHON = ">=3.7.0"
15+
VERSION = None
16+
17+
18+
def get_requirements(source: str = "requirements.txt"):
19+
requirements = []
20+
with open(source) as f:
21+
for line in f:
22+
package, _, comment = line.partition("#")
23+
package = package.strip()
24+
if package:
25+
requirements.append(package)
26+
27+
return requirements
28+
29+
30+
REQUIRED = get_requirements("requirements.txt")
31+
32+
# The rest you shouldn't have to touch too much :)
33+
# ------------------------------------------------
34+
# Except, perhaps the License and Trove Classifiers!
35+
# If you do change the License, remember to change the Trove Classifier for that!
36+
37+
here = os.path.abspath(os.path.dirname(__file__))
38+
39+
# Import the README and use it as the long-description.
40+
# Note: this will only work if 'README.md' is present in your MANIFEST.in file!
41+
try:
42+
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
43+
long_description = "\n" + f.read()
44+
except FileNotFoundError:
45+
long_description = DESCRIPTION
46+
47+
# Load the package's __version__.py module as a dictionary.
48+
about = {}
49+
if not VERSION:
50+
prefix = "src"
51+
project_slug = NAME.lower().replace("-", "_").replace(" ", "_")
52+
with open(os.path.join(here, prefix, project_slug, "__init__.py")) as f:
53+
exec(f.read(), about)
54+
else:
55+
about["__version__"] = VERSION
56+
57+
# Where the magic happens:
58+
setup(
59+
name=NAME,
60+
version=about["__version__"],
61+
description=DESCRIPTION,
62+
long_description=long_description,
63+
long_description_content_type="text/markdown",
64+
author=AUTHOR,
65+
author_email=EMAIL,
66+
python_requires=REQUIRES_PYTHON,
67+
url=URL,
68+
packages=find_packages("src"),
69+
# package_dir={"cicflowmeter": "src/cicflowmeter"},
70+
package_dir={"": "src"},
71+
entry_points={
72+
"console_scripts": ["cicflowmeter=cicflowmeter.sniffer:main"],
73+
},
74+
install_requires=REQUIRED,
75+
include_package_data=True,
76+
license="MIT",
77+
classifiers=[
78+
"License :: OSI Approved :: MIT License",
79+
"Programming Language :: Python",
80+
"Programming Language :: Python :: 3",
81+
"Programming Language :: Python :: 3.7",
82+
"Programming Language :: Python :: Implementation :: CPython",
83+
"Programming Language :: Python :: Implementation :: PyPy",
84+
],
85+
)

src/cicflowmeter/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.6"

src/cicflowmeter/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
EXPIRED_UPDATE = 240
2+
CLUMP_TIMEOUT = 1
3+
ACTIVE_TIMEOUT = 0.005
4+
BULK_BOUND = 4

0 commit comments

Comments
 (0)