Coder Social home page Coder Social logo

network_interface's People

Contributors

adfoster-r7 avatar dwelch-r7 avatar sjanusz-r7 avatar timwr avatar todb avatar tux-mind avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

network_interface's Issues

Export AF_ variables

Could you export the AF_ variables (especially AF_INET, AF_INET6 and AF_LINK) so that I can figure out which families are which when using NetworkInterface.addresses.

Solaris10

Any chance on adding netifaces.h Solaris definitions ?

Need to figure out the correct definitions for it here

if !HAVE_GETIFADDRS && (!HAVE_SOCKET_IOCTLS || !HAVE_SIOCGIFCONF)

/* If the platform doesn't define, what we need, barf. If you're seeing this,
it means you need to write suitable code to retrieve interface information
on your system. */

error You need to add code for your platform.

endif

Add support for .first and .filter(q: "foo")

Refactoring and replace.

    addrs = NetworkInterface.addresses(value).values.flatten

    # Strip interface name from address (see getifaddrs(3))
    addrs = addrs.map { |x| x['addr'].split('%').first }.select do |addr|
      begin
        IPAddr.new(addr).ipv4? && !addr[/^127.*/]
      rescue IPAddr::InvalidAddressError
        false
      end
    end

    addrs.any? ? addrs.first : ''

and

  iface = NetworkInterface.interfaces.collect do |iface|
    ip_address = NetworkInterface.addresses(iface).values.flatten.collect{|x| x['addr']}.select do |addr|
      begin
        IPAddr.new(addr).ipv4? && !addr[/^127.*/]
      rescue IPAddr::InvalidAddressError => e
        false
      end
    end.first
    {name: iface, addr: ip_address}
  end.select {|ni| ni[:addr]}.first

References:

  1. https://github.com/rapid7/metasploit-framework/blob/102db261026058d017e20b9a04399bdf1cb6d7b4/lib/msf/core/opt_address_local.rb#L21-L32

  2. https://github.com/rapid7/metasploit-framework/blob/master/spec/lib/msf/core/opt_address_local_spec.rb#L7-L16

Pick an interface based on a target IP

As a user, I would like to be able to communicate to NetworkInterface the IP address I'm trying to reach. You can determine which is the best interface based on the routing table.

The code should look something like:

ipaddr = '127.1.1.1'
NetworkInterface.pick_interface(ipaddr) # => 'lo'
ipaddr = '10.0.0.1'
NetworkInterface.pick_interface(ipaddr) # => 'eth0'
ipaddr = '8.8.8.8'
NetworkInterface.pick_interface(ipaddr) # => 'wlan0'

Something like that.

cc @sho-luv

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.