← Back to team overview

indiv-screenlets-dev team mailing list archive

[Bug 241557] Re: [Sensors] screenlets.sensors.net_get_ip() doesn't necessarily return the correct value

 

** Changed in: indiv-screenlets
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of
Individual Screenlets Developers, which is subscribed to Individual
Screenlets.
https://bugs.launchpad.net/bugs/241557

Title:
  [Sensors] screenlets.sensors.net_get_ip() doesn't necessarily return
  the correct value

Status in Screenlets — individual widgets development:
  Fix Released

Bug description:
  screenlets.sensors.net_get_ip() doesn't necessarily return the correct
  IP address. A modern Linux system likely has at least three IPs:
  127.0.0.1 (which net_get_ip() ignores), the avahi IP, and the regular
  IP. The function sometimes grabs the IP for the device eth0:avahi on
  my machine instead of the correct device: wlan0. But if I was plugged
  in to a wired connection, the correct device would be eth0. Of course,
  people who use avahi might want to get the avahi IP instead of wlan0
  or eth0 or whatever. So I think that net_get_ip() should instead
  return a dictionary of all IPs except 127.0.0.1 and let the individual
  screenlet (such as Sysmonitor) decide which interface(s) to use.

  I'm not convinced that parsing ifconfig is the best way to get at the
  IP address, but I can't think of something better. Here's some sample
  code (in Ruby because I don't know Python very well. It shouldn't be
  too hard to translate for someone who knows Python better than I do.)

  def net_get_ip()
      dict = {}
      iface = nil
      
      `ifconfig`.chomp.split("\n").each do |line|
          if line =~ /^([^\s]+)/   # If the line begins with a non-whitespace character, then it identifies an interface
              iface = $1 # This refers to the interface name matched in the regexp above
              iface = nil if iface == 'lo' # Skip the loopback interface
          elsif iface
              if line =~ /inet addr:[\s]?([0-9.]+)/
                  dict[iface] = $1 # Again, $1 refers to the IP address matched by the regexp
              end
             iface = nil
          end
      end

      return dict
  end

To manage notifications about this bug go to:
https://bugs.launchpad.net/indiv-screenlets/+bug/241557/+subscriptions