Giter Club home page Giter Club logo

nic_traffic's Introduction

NIC_traffic

Project Description:

In this project, I am planning to capture packets from a machine. Then capture packets will be parsed in order to acquire the proper results. We only process the *TCP* and *UDP* packets and others such as ICMP packets are labeled **Unknown**

Technologies which are used:

1- Python 3.5
2- No library(for further update I will use scapy)
3- Sockets

How the process is done?

It is possible to use scapy for the whole project but, first, everything is coded here and we will pay attention to scapy after finishing our own packet sniffer.
Since we are accessing the packets, it is needed to run the code with Sudo in order to receive the permission.
For capturing the pockets I am using the socket module. Python programming language socket module provides us the facility to play with network concept.
There is a small difference in Python socket module codes based on operating systems.
Here we use it for Linux. So, we have to run the python file with sudo.

Parsing process:

According to the Ethernet Frame Format Diagram, I am going to extract the demanded properties. I have to pass an argument that going to represent field types, we want to extract in (struct.unpack) function. The IP, TCP, UDP etc header information will be saved in a struct.
An example of formats:

storeobj = struct.unpack("!BBHHHBBH4s4s", data)

Here! means that receiver always receive data in reverse order. H is for Unsigned Short data types and the number is for the times to use.

In these line of codes, we determine which kind of IP packets we have:

if proto == '80':
ip_proto = 'IPv4'
elif proto == '86':
ip_proto = 'ARP'
elif proto == '86DD':
ip_proto = 'IPv6'
else: </br> ip_proto = proto </br>

We have a number when we parse it we can figure out which kind of packets we have. If it is 6 then its TCP, or it is 17 we have UDP. Then we extract the source and destination Ip. Source port and destination port are selected when it is defined we have TCP or UDP.

For every packet that we parse, the demanded information will be stored in the dictionary for making the flow. As I found out on the internet, traffic flow, packet flow or network flow is a sequence of packets from a source computer to a destination, which may be another host, a multicast group, or a broadcast domain. We need to group these packets and calculate the features which are demanded.
To make the flow of packets, I check if the source IP and DestIP are the same or not. IF they are the same we store packets in lists and we calculate the duration of it and number bytes which it sends.

After that, We will write all the information that we have into the CSV_file.

Still working on the project.

nic_traffic's People

Contributors

masoudslipknot avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.