https://github.com/fijxu/natpmp-crystal
Crystal library implementation of RFC 6886 (NAT-PMP), client side.
https://github.com/fijxu/natpmp-crystal
client crystal library nat-pmp rfc-6886 simple
Last synced: 5 months ago
JSON representation
Crystal library implementation of RFC 6886 (NAT-PMP), client side.
- Host: GitHub
- URL: https://github.com/fijxu/natpmp-crystal
- Owner: Fijxu
- License: mit
- Created: 2024-12-29T23:14:01.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-13T14:21:45.000Z (over 1 year ago)
- Last Synced: 2025-02-20T04:41:31.878Z (over 1 year ago)
- Topics: client, crystal, library, nat-pmp, rfc-6886, simple
- Language: Crystal
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# natpmp-crystal
Work in progress implementation of RFC 6886 **NAT Port Mapping Protocol (NAT-PMP)**, client side.
Since RFC 6886 is a pretty simple protocol, it should be ready to use to requests mappings
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
natpmp-crystal:
github: fijxu/natpmp-crystal
```
2. Run `shards install`
## Usage
```crystal
# Create NAT-PMP client, replace the IP by the IP of your
# gateway
client = NatPMP::Client.new("192.168.1.1")
# Public address request
client.send_public_address_request # => {0, 128, 0, 22758, "104.0.0.0"}
client.send_public_address_request_as_bytes # => Bytes[0, 128, 0, 0, 0, 0, 88, 230, 104, 0, 0, 0]
# Maps the internal port 25565 to external port 25565, TCP
client.request_mapping(25565, 25565, 2) # => {0, 130, 0, 22758, 25565, 25565, 7200}
# Destroys the mapping with internal port 25565, TCP
client.destroy_mapping(25565, 2) # => {0, 130, 0, 22758, 25565, 0, 0}
# Maps the internal port 22000 to external port 22000, UDP
client.request_mapping(22000, 22000, 1) # => {0, 129, 0, 22758, 22000, 22000, 7200}
# Destroys the mapping with internal port 22000, UDP
client.destroy_mapping(22000, 1) # => {0, 129, 0, 22758, 22000, 0, 0}
```
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Fijxu](https://github.com/fijxu) - creator and maintainer