Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arcage/net_sample.cr
https://github.com/arcage/net_sample.cr
crystal
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/arcage/net_sample.cr
- Owner: arcage
- License: mit
- Created: 2018-12-10T23:40:39.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-13T15:24:19.000Z (almost 4 years ago)
- Last Synced: 2023-08-08T07:31:31.021Z (over 1 year ago)
- Topics: crystal
- Language: Crystal
- Size: 27.3 KB
- Stars: 6
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Network programing samples for the Crystal language
This shard includes following sample codes.
- Gets following informations of the ethernet interfaces.
- hardware address a.k.a. MAC address or phisical address
- IPv4 address
- IPv6 address_Tested on gnu(CentOS8)/musl(official alpine linux image) linux and and BSD(Mac OS 10.14)._
- `ping` like command
Sends ICMP ECHO request and receive its REPLY.
_NOTE: Included codes are not practical but only samples._
## Installation
1. Add the dependency to your `shard.yml`
```yaml
dependencies:
net_sample:
github: arcage/net_sample.cr
```
2. Run `shards install`## Usage
```crystal
require "net_sample"# get interface names
NetSample::NIC.ifnames
#=> ["lo0", "eth1"]puts eth1 = NetSample::NIC["eth1"]
#=># ping like command(require root privirage)
NetSample::Ping.command("192.0.2.1")
#=>
# PING 192.0.2.1: 56 data bytes
# 64 bytes from 192.0.2.1: icmp_seq=0 ttl=253 time=1.903 ms
# 64 bytes from 192.0.2.1: icmp_seq=1 ttl=253 time=1.466 ms
# 64 bytes from 192.0.2.1: icmp_seq=2 ttl=253 time=1.355 ms
# 64 bytes from 192.0.2.1: icmp_seq=3 ttl=253 time=2.115 ms
# 64 bytes from 192.0.2.1: icmp_seq=4 ttl=253 time=2.074 ms
#
# --- 192.0.2.1 ping statistics ---
# 5 packets transmitted, 5 packets received, 0% packet loss
# round-trip min/avg/max/stddev = 1.355/1.783/2.115/0.346 ms
```## Contributors
- [ʕ·ᴥ·ʔAKJ](https://github.com/arcage) - creator and maintainer