Skip to content

Commit

Permalink
Kill external IP cache if # of interfaces changes.
Browse files Browse the repository at this point in the history
 - Quick and dirty way to pick up external IP changes on VPN connections
  • Loading branch information
Andrew Burns committed Jul 11, 2012
1 parent 77fc1b5 commit fca116d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion current_ips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ def get_external_ip cache_entry

def get_ips cache_entry
ips = []
interfaces = Network.interface_list

## See if the interface count has changed, if it has, then throw away the cache
cache_entry[:external_ip] = '' if cache_entry[:if_count].to_s.empty? || cache_entry[:if_count].to_i != interfaces.size
cache_entry[:if_count] = interfaces.size ## Save current list

external_ip = get_external_ip cache_entry
if external_ip.empty?
ips << ['No Active Interfaces', '']
else
ips << ['world', external_ip]
end
Network.interface_list.each do |iif|
interfaces.each do |iif|
iif[:status] = :active if iif[:name] =~ /^(utun|ppp)/i
next if iif[:status] != :active || iif[:ip].to_s.empty?
next if iif[:name] =~ /(?:lo\d+|vmnet\d+)/i # Ignored interfaces
Expand Down

0 comments on commit fca116d

Please sign in to comment.