Coder Social home page Coder Social logo

inet_ext's Introduction

inet_ext

inet extension, collections of convenient functions to use with inet

Usage

Get the lists of default gateway for each interfaces

1> inet_ext:gateways().
[{"en0","192.168.1.254"},{"en1","192.168.1.254"}]

To get the gateway for a specific interface uses the inet_ext:gateway_for/1 function.

Get internal address for a gateway

2> inet_ext:get_internal_address("192.168.1.254").
"192.168.1.22"

Get all routes

3> inet_ext:routes().
[{"lo0",
  {{65152,0,0,0,0,0,0,1},{65535,65535,65535,65535,0,0,0,0}}},
 {"lo0",{{127,0,0,1},{255,0,0,0}}},
 {"lo0",
  {{0,0,0,0,0,0,0,1},
   {65535,65535,65535,65535,65535,65535,65535,65535}}},
 {"en0",{{192,168,1,41},{255,255,255,0}}},
 {"en0",
  {{10753,3637,35380,28048,9323,2852,13025,48991},
   {65535,65535,65535,65535,0,0,0,0}}},
 {"en0",
  {{10753,3637,35380,28048,44679,41983,65072,60656},
   {65535,65535,65535,65535,0,0,0,0}}},
 {"en0",
  {{65152,0,0,0,44679,41983,65072,60656},
   {65535,65535,65535,65535,0,0,0,0}}},
 {"en1",{{192,168,1,22},{255,255,255,0}}},
 {"en1",
  {{10753,3637,35380,28048,24909,3247,60839,4143},
   {65535,65535,65535,65535,0,0,0,0}}}]

IP and MAC address format conversions

API Description
convert_mac/2 Convert MAC Address from -> to
convert_ip/2 Convert IP Address from -> to

Conversions allowed are in between following types: to_string | to_binstring | to_integer | to_binary | to_list | to_tuple

1> inet_utils:convert_mac(to_binstring, <<1,2,3,4,5,6>>).
<<"01:02:03:04:05:06">>
2> inet_utils:convert_ip(to_binary, 16#01020304).
<<1,2,3,4>>

Check address type

You can test an IP address to know if they it's a private, global(public), loopback, reserved, unspecified, liknlocal or multicast address by using the following functions:

* `is_private_address/1`
* `is_global_address/1`
* `is_loopback_address/1`
* `is_unspecified_address/1`
* `is_reserved_address/1`
* `is_linklocal_address/1`
* `is_multicast_address/1`

These functions are using based on IANA IPv4 & IPv6 special-purpose address registries.

1> inet_ext:is_private_address("192.168.1.1").
true

Contribute

For issues, comments or feedback please create an issue.

inet_ext's People

Contributors

benoitc avatar vasu-dasari avatar vagabond avatar

Stargazers

Khalil Heyrani avatar Qiu Hua avatar kyle avatar  avatar Gregory Ostermayr avatar  avatar Bryan FRIMIN avatar Sam Gaw avatar Igor K avatar Mikal avatar Kenji Rikitake avatar nonblockio avatar Engr Saad avatar Leonardo Rossi avatar

Watchers

 avatar James Cloos avatar href avatar  avatar

inet_ext's Issues

Failure on PPP interfaces

When we're dialing via a PPP interface:

$ ip r
default dev ppp0 scope link 
10.59.4.14 dev ppp0 scope link 
169.254.0.0/16 dev ppp0 scope link  src 169.254.172.203

So ip r | grep ppp0 | grep default | sed 's/^none //' | cut -d ' ' -f 3 returns, instead of an IP, ppp0, which is not a parsable IP and it triggers an {error, einval}

MAC and IP Conversion tools

Hi,

I was looking for some utilities to convert MAC and IP addresses from one form(list to binary, etc) to other. I created a project to accomplish the same. The plan is to enhance this project with more APIs I might need. It is at https://github.com/vasu-dasari/inet_utils.

I came across your repository, which I feel could also host the same APIs. I do not mind putting my code in your repository if you think your repository can be a right place to the APIs provided under my repository.

Please let me know.

Strange stderr errors

When using inet_ext via erlang-nat we sometimes see messages on stderr like this:

erl_child_setup: failed with error 32 on line 253
cut: write error: Broken pipe

They don't appear consistently, and I'm not sure why.

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.