diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-15 11:28:10 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-15 11:28:10 +0000 |
commit | a31ab93a019f6c696c262d7cb53d867ec7ae2594 (patch) | |
tree | 70cfecebd842513c6997d4d6c12a592b982a40ea /lib | |
parent | 94cffe6681e85ac399d0c2a24bf6987e00705834 (diff) |
Don't resolve IPs
Diffstat (limited to 'lib')
-rw-r--r-- | lib/custodian/alerter.rb | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/custodian/alerter.rb b/lib/custodian/alerter.rb index f5caa6a..8bbd47e 100644 --- a/lib/custodian/alerter.rb +++ b/lib/custodian/alerter.rb @@ -43,29 +43,43 @@ class Alerter # resolved = nil + # - # Resolve the target to an IP + # Resolve the target to an IP, unless it is already an address. # - begin - Socket.getaddrinfo(target, 'echo').each do |a| - resolved = a[3] if ( a ) + if ( ( target =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || + ( target =~ /^([0-9a-f:]+)$/ ) ) + resolved = target + else + begin + Socket.getaddrinfo(target, 'echo').each do |a| + resolved = a[3] if ( a ) + end + rescue SocketError + resolved = nil end - rescue SocketError end + # + # Did we get an error? + # return "" unless ( !resolved.nil? ) + + # + # Make any HTTP target a link in the details. + # if ( host =~ /^http/ ) host = "<a href=\"#{host}\">#{host}</a>" end # - # Test trange + # Test trange, and format the appropriate message. # if ( BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(resolved.to_s))} ) return "<p>#{host} resolves to <tt>#{resolved}</tt> which is inside the Bytemark network.</p>" else - return "<p>#{host} resolves to <tt>#{resolved}</tt> which <b>is not</b> inside the Bytemark network.</p>" + return "<p>#{host} resolves to <tt>#{resolved}</tt> which is not inside the Bytemark network.</p>" end end |