Coder Social home page Coder Social logo

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.

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

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

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

Windows support issues

The Gem doesn't support:

  • Compiling on Windows 64 - the RUBY_PLATFORM is x64-mingw32
  • Doesn't support retrieving IPV6 addresses, the library should be using GetAdaptersAddresses to retrieve this information

Debugging steps to replicate/have rake compile working

diff --git a/ext/network_interface_ext/extconf.rb b/ext/network_interface_ext/extconf.rb
index 7e2ee42..1968382 100644
--- a/ext/network_interface_ext/extconf.rb
+++ b/ext/network_interface_ext/extconf.rb
@@ -7,13 +7,14 @@ extension_name = 'network_interface_ext'
 puts "\n[*] Running checks for netifaces code..."
 #uncoment to force ioctl on non windows systems
 #@force_ioctl = true
-@supported_archs = [ "i386-mingw32", "i486-linux", "x86_64-linux",
+@supported_archs = [ "i386-mingw32", "x64-mingw32", "i486-linux", "x86_64-linux",
   "universal-darwin10.0", "i386-openbsd4.8", "i386-freebsd8",
   "arm-linux-eabi", "x86_64-darwin12.3.0" ]
 #arm-linux-eabi tested on maemo5 / N900
 puts "[*] Warning : this platform as not been tested" unless @supported_archs.include? RUBY_PLATFORM

-if RUBY_PLATFORM =~ /i386-mingw32/
+require 'pry-byebug'; binding.pry
+if RUBY_PLATFORM =~ /i386-mingw32|x64-mingw32/
   unless  have_library("ws2_32" ) and
       have_library("iphlpapi") and
       have_header("windows.h") and
@@ -92,4 +93,4 @@ $defs = $defs.map do |a|
   end
 end

-create_makefile(extension_name)
\ No newline at end of file
+create_makefile(extension_name)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index b247187..7f313da 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -24,25 +24,27 @@ def friendly_interface_names
   interface_names
 end

-if RUBY_PLATFORM =~ /i386-mingw32/
+if RUBY_PLATFORM =~ /i386-mingw32|x64-mingw32/
   def system_interfaces
     ipconfig = `ipconfig`
     ipconfig_array = ipconfig.split("\n").reject {|s| s.empty?}
-
+
     getmac = `getmac -nh`
     getmac_array = getmac.split("\n").reject {|s| s.empty?}
     getmac_array.map!{|element| element.split(" ")}
     getmac_hash = getmac_array.inject({}) do |hash, array|
       hash.merge!({array[1][/\{(.*)\}/,1] => array[0].gsub("-",":").downcase})
     end
-
+
     interfaces = {}
     @key = nil
     ipconfig_array.each do |element|
       if element.start_with? " "
         case element
         when /IPv6 Address.*: (.*)/
-          # interfaces[@key][:ipv6] = $1
+          # require 'pry-byebug'; binding.pry
+          # puts '123'
+          interfaces[@key][:ipv6] = $1
         when /IPv4 Address.*: (.*)/
           interfaces[@key][:ipv4] = $1
           interfaces[@key][:mac] = getmac_hash[@key[/\{(.*)\}/,1]]
@@ -56,11 +58,11 @@ if RUBY_PLATFORM =~ /i386-mingw32/
         interfaces[@key] = {}
       end
     end
-
+
     interfaces
   end

-else
+else
   def system_interfaces
     ifconfig = `/sbin/ifconfig`
     ifconfig_array = ifconfig.split("\n")

Note - when compiling on windows we needed to add ridk in the current prompt for the ruby developer kit to be on the path

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.