[Sensors] screenlets.sensors.net_get_ip() doesn't necessarily return the correct value
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Individual Screenlets |
Fix Released
|
Low
|
Unassigned |
Bug Description
screenlets.
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`
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:[\
end
iface = nil
end
end
return dict
end
description: | updated |
affects: | screenlets → indiv-screenlets |
summary: |
- screenlets.sensors.net_get_ip() doesn't necessarily return the correct - value + [Sensors] screenlets.sensors.net_get_ip() doesn't necessarily return the + correct value |
Changed in indiv-screenlets: | |
status: | New → Fix Committed |
Changed in indiv-screenlets: | |
importance: | Undecided → Low |
Changed in indiv-screenlets: | |
status: | Fix Committed → Fix Released |
Hello Scott,
i think this is the best way,
and also it should be localized because in my german environment the is no result
because of die localized output of ifconfig.
My workaround is to call LC_ALL=C ifconfig
so I changed to getoutput( "LC_ALL= C ifconfig") find(chr( 32))]
def net_get_ip(): # by Whise
"""Returns ip if it can"""
ip = commands.
x = 0
while True:
ip = ip[ip.find("inet addr:"):]
ip = ip[10:]
ipc = ip[:ip.
if ipc != '127.0.0.1' and ipc != None and ipc !='1':
return _('Cannot get ip')