rapid7 / network_interface Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
Add dependency - pry to .gemspec.
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.
Hi,
@bcook-r7
can you please push a git tag for the commit that is published on rubygems as 0.0.2?
Thanks a lot
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:
Any chance on adding netifaces.h Solaris definitions ?
Need to figure out the correct definitions for it here
/* 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. */
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
The Gem doesn't support:
RUBY_PLATFORM
is x64-mingw32
GetAdaptersAddresses
to retrieve this informationDebugging 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.