rapid7 / network_interface Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
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
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.
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. */
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:
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
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.