This library allows you to implemnet a custom layer 2 communication using raw sockets in Python 2 and Python 3, synchronous and asynchronous, with and without callbacks.
Project description
# RawSocketPy
Raw socket is a layer 2 python library for communication using the MAC addresses only.
This allows you to create a custom made Ethernet/WiFi communication system which is **not** using IP nor TCP/UDP or to debug custom frames such as SERCOS III, Profibus, ARP, PTP, ...
Python versions tested:
- [x] 2.7.x
- [x] 3.5.x
OSes:
- [ ] Linux 14.04
- [x] Linux 16.04
- [ ] Linux 18.04
- [ ] Windows 10
- [ ] Mac OSX
**Pros:**
- Low level
- Not using TCP-UDP/IP
- Dead simple
- Can broadcast
- MTU of 1500
**Cons:**
- Low level
- Not using TCP-UDP/IP
- No encryption
- No fragmentation
- **Requires root**
- MTU of 1500
## Installation
```bash
# Soon
sudo -H pip install rawsocketpy
# for now:
git clone https://github.com/AlexisTM/rawsocket_python
cd rawsocket_python
sudo python setup.py install
```
## Fast testing
On one computer:
```bash
sudo python -c "from rawsocketpy import RawSocket
sock = RawSocket('wlp2s0', 0xEEFA)
while True: print(sock.recv())"
# 12:34:56:78:9A:BC == 0xEEFA => FF:FF:FF:FF:FF:FF - OK:
# Boo
```
On the second computer over the same router:
```bash
sudo python -c "from rawsocketpy import RawSocket; import time
sock = RawSocket('wlp2s0', 0xEEFA)
while True:
sock.send('Boo')
print('Boo has been sent')
time.sleep(0.5)"
```
## In-depth
```python
from rawsocketpy import RawSocket
# 0xEEFA is the ethertype
# The most common are available here: https://en.wikipedia.org/wiki/EtherType
# The full official list is available here: https://regauth.standards.ieee.org/standards-ra-web/pub/view.html#registries
# Direct link: https://standards.ieee.org/develop/regauth/ethertype/eth.csv
# You can use whatever you want but using a already use type can have unexpected behaviour.
sock = RawSocket("wlp2s0", 0xEEFA)
sock.send("some data") # Broadcast "some data" with an ethertype of 0xEEFA
sock.send("personal data", dest="\xAA\xBB\xCC\xDD\xEE\xFF") # Send "personal data to \xAA\xBB\xCC\xDD\xEE\xFF with an ether type of 0xEEFA
sock.send("other data", ethertype="\xEE\xFF") # Broadcast "other data" with an ether type of 0xEEFF
```
### Receiving
On another machine, you can run the following:
```python
from rawsocketpy import RawSocket, u_to_str
sock = RawSocket("wlp2s0", 0xEEFA)
packet = sock.recv()
# The type of packet is RawPacket() which allows pretty printing and unmarshal the raw data.
print(packet) # Pretty print
packet.dest # unicode string "\xFF\xFF\xFF\xFF\xFF\xFF"
packet.src # unicode string "\x12\x12\x12\x12\x12\x13"
packet.type # unicode string "\xEE\xFA"
packegt.data # unicode string "some data"
print u_to_str(packet.dest) # Human readable MAC: FF:FF:FF:FF:FF:FF
print u_to_str(packet.type, "") # Human readable type: EEFA
```
## I want to contribue!!
You are free to contribue, the following capabilities are welcome:
- Windows compatibility
- Async implementation (callbacks on new data)
- Readthedocs documentation
- More Python versions and OS tests
## Credits
- Alexis PAQUES - [@AlexisTM](https://github.com/AlexisTM/)
Raw socket is a layer 2 python library for communication using the MAC addresses only.
This allows you to create a custom made Ethernet/WiFi communication system which is **not** using IP nor TCP/UDP or to debug custom frames such as SERCOS III, Profibus, ARP, PTP, ...
Python versions tested:
- [x] 2.7.x
- [x] 3.5.x
OSes:
- [ ] Linux 14.04
- [x] Linux 16.04
- [ ] Linux 18.04
- [ ] Windows 10
- [ ] Mac OSX
**Pros:**
- Low level
- Not using TCP-UDP/IP
- Dead simple
- Can broadcast
- MTU of 1500
**Cons:**
- Low level
- Not using TCP-UDP/IP
- No encryption
- No fragmentation
- **Requires root**
- MTU of 1500
## Installation
```bash
# Soon
sudo -H pip install rawsocketpy
# for now:
git clone https://github.com/AlexisTM/rawsocket_python
cd rawsocket_python
sudo python setup.py install
```
## Fast testing
On one computer:
```bash
sudo python -c "from rawsocketpy import RawSocket
sock = RawSocket('wlp2s0', 0xEEFA)
while True: print(sock.recv())"
# 12:34:56:78:9A:BC == 0xEEFA => FF:FF:FF:FF:FF:FF - OK:
# Boo
```
On the second computer over the same router:
```bash
sudo python -c "from rawsocketpy import RawSocket; import time
sock = RawSocket('wlp2s0', 0xEEFA)
while True:
sock.send('Boo')
print('Boo has been sent')
time.sleep(0.5)"
```
## In-depth
```python
from rawsocketpy import RawSocket
# 0xEEFA is the ethertype
# The most common are available here: https://en.wikipedia.org/wiki/EtherType
# The full official list is available here: https://regauth.standards.ieee.org/standards-ra-web/pub/view.html#registries
# Direct link: https://standards.ieee.org/develop/regauth/ethertype/eth.csv
# You can use whatever you want but using a already use type can have unexpected behaviour.
sock = RawSocket("wlp2s0", 0xEEFA)
sock.send("some data") # Broadcast "some data" with an ethertype of 0xEEFA
sock.send("personal data", dest="\xAA\xBB\xCC\xDD\xEE\xFF") # Send "personal data to \xAA\xBB\xCC\xDD\xEE\xFF with an ether type of 0xEEFA
sock.send("other data", ethertype="\xEE\xFF") # Broadcast "other data" with an ether type of 0xEEFF
```
### Receiving
On another machine, you can run the following:
```python
from rawsocketpy import RawSocket, u_to_str
sock = RawSocket("wlp2s0", 0xEEFA)
packet = sock.recv()
# The type of packet is RawPacket() which allows pretty printing and unmarshal the raw data.
print(packet) # Pretty print
packet.dest # unicode string "\xFF\xFF\xFF\xFF\xFF\xFF"
packet.src # unicode string "\x12\x12\x12\x12\x12\x13"
packet.type # unicode string "\xEE\xFA"
packegt.data # unicode string "some data"
print u_to_str(packet.dest) # Human readable MAC: FF:FF:FF:FF:FF:FF
print u_to_str(packet.type, "") # Human readable type: EEFA
```
## I want to contribue!!
You are free to contribue, the following capabilities are welcome:
- Windows compatibility
- Async implementation (callbacks on new data)
- Readthedocs documentation
- More Python versions and OS tests
## Credits
- Alexis PAQUES - [@AlexisTM](https://github.com/AlexisTM/)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rawsocketpy-0.2.tar.gz
(4.8 kB
view hashes)
Built Distributions
Close
Hashes for rawsocketpy-0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffd7f9d9964c9885d3cbb774f27a1f4764bfb08a22b00c1cf8b041cfefee1b29 |
|
MD5 | 0f00a1c2dbd33b1da72464225a746dfb |
|
BLAKE2b-256 | 133b244f69bb1a361c6470c1383f0ed0120d3c72f50b1986089fe838902dcd0b |
Close
Hashes for rawsocketpy-0.2-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1f05335a3edde8bf7c9ed254d71c2028ecc5ed6742045db1a7a58b56e656b71 |
|
MD5 | 1f04dbb85d77c10d27c03dc6aab9a39b |
|
BLAKE2b-256 | 63194581f3c223837e3007817516dca6486f0aee550dc7eb8f2f83eef5bd00b7 |